Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created June 12, 2012 16:00
Show Gist options
  • Save tmcw/2918389 to your computer and use it in GitHub Desktop.
Save tmcw/2918389 to your computer and use it in GitHub Desktop.
process hyg star database into a shapefile with shapely and fiona
import shapely
import fiona
from fiona import collection
import csv
star_csv = csv.reader(open('hygxyz.csv', 'rb'))
header = star_csv.next()
max_x = 10000000
min_x = -10000000
max_y = 10000000
min_y = -10000000
"""
x: 17
y: 18
"""
schema = {
'geometry': 'Point',
'properties': {
'MAG': 'float',
'COLOR': 'float',
'NAME': 'str',
}
}
world_width = 20037508.34 * 2
# Open a new sink for features, using the same format driver
# and coordinate reference system as the source.
with collection(
"stars_4.shp", "w",
crs = {
"type": "name",
"properties": {
"name": "EPSG:900913"
}
},
driver = "ESRI Shapefile",
schema = schema) as sink:
for row in star_csv:
x = float(row[17])
y = float(row[18])
lon = ( ( (x - min_x) / (max_x - min_x) ) * world_width - (world_width / 2) )
lat = ( ( (y - min_y) / (max_y - min_y) ) * world_width - (world_width / 2) )
if row[16]:
color_index = float(row[16])
else:
color_index = 0
abs_magnitude = float(row[14])
proper_name = row[6]
f = {
"properties": {
"MAG": abs_magnitude,
"NAME": proper_name,
"COLOR": color_index
},
"geometry": {
"type": "Point",
"coordinates": [lon, lat]
}
}
sink.write(f)
Map {
background-color: #111;
}
#stars {
marker-line-width:0;
marker-allow-overlap:true;
[COLOR <= 0] {
marker-fill:#DDFFFC;
}
[COLOR > 0][COLOR <= 0.5] {
marker-fill:#B9FFF9;
}
[COLOR > 0.5] {
marker-fill:#FFEBA8;
}
[MAG < -8] { marker-width:1; }
[MAG > -8][MAG < -6] { marker-width:2; }
[MAG > -6][MAG < -4] { marker-width:3; }
[MAG > -4][MAG < -2] { marker-width:4; }
[MAG > -2][MAG < 0] { marker-width:5; }
[MAG > 0][MAG < 0.5] { marker-width:6; }
[MAG > 0.5][MAG < 1] { marker-width:6; }
[MAG > 1][MAG < 3] { marker-width:7; }
[MAG > 6] { marker-width:8; }
[zoom > 5] {
text-name:'[NAME]';
text-face-name:'CMU Serif Roman';
text-dy:15;
text-size:12;
text-fill:#EBEBEB;
}
}
@tmcw
Copy link
Author

tmcw commented Jun 13, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment