Skip to content

Commit

Permalink
Merge pull request #82 from EvansMike/master
Browse files Browse the repository at this point in the history
I've added a points layer and some other minor fixes.  Hope these are useful.
  • Loading branch information
gka committed Mar 10, 2013
2 parents 63b5e07 + 4522c7a commit 4b323f1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 4 additions & 4 deletions kartograph/layersource/shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,7 @@ def __record(self):
# deleted record
return None
record = []
for (name, typ, size, deci), value in zip(self.fields,
recordContents):
for (name, typ, size, deci), value in zip(self.fields, recordContents):
if name == 'DeletionFlag':
continue
elif not value.strip():
Expand All @@ -378,7 +377,8 @@ def __record(self):
except:
value = 0
else:
value = int(value)
try:value = int(float(value))
except: value = 0
elif typ == b('D'):
try:
y, m, d = int(value[:4]), int(value[4:6]), int(value[6:8])
Expand Down Expand Up @@ -999,4 +999,4 @@ def test():
testing libraries but for now unit testing is done using what's available in
2.3.
"""
test()
test()
16 changes: 14 additions & 2 deletions kartograph/layersource/shplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_features(self, attr=None, filter=None, bbox=None, ignore_holes=False, mi
def shape2geometry(shp, ignore_holes=False, min_area=False, bbox=False, proj=None):
if shp is None:
return None
if bbox:
if bbox and shp.shapeType != 1:
if proj:
left, top = proj(shp.bbox[0], shp.bbox[1], inverse=True)
right, btm = proj(shp.bbox[2], shp.bbox[3], inverse=True)
Expand All @@ -153,6 +153,8 @@ def shape2geometry(shp, ignore_holes=False, min_area=False, bbox=False, proj=Non
geom = shape2polygon(shp, ignore_holes=ignore_holes, min_area=min_area, proj=proj)
elif shp.shapeType in (3, 13): # line
geom = shape2line(shp, proj=proj)
elif shp.shapeType == 1: # point
geom = shape2point(shp, proj=proj)
else:
raise KartographError('unknown shape type (%d)' % shp.shapeType)
return geom
Expand Down Expand Up @@ -241,7 +243,17 @@ def shape2line(shp, proj=None):
else:
raise KartographError('shapefile import failed - no line found')


def shape2point(shp, proj=None):
from shapely.geometry import MultiPoint, Point
points = shp.points[:]
if len(points) == 1:
return Point(points[0])
elif len(points) > 1:
return MultiPoint(points)
else:
raise KartographError('shapefile import failed - no points found')


def project_coords(pts, proj):
for i in range(len(pts)):
x, y = proj(pts[i][0], pts[i][1], inverse=True)
Expand Down
2 changes: 1 addition & 1 deletion kartograph/mapstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def remove_unit(val):
}
*[highway=primary] {
stroke-wigth: 4px;
stroke-width: 4px;
}
'''
Expand Down

0 comments on commit 4b323f1

Please sign in to comment.