Tag Info

New answers tagged

1

1) With Fiona, you don't need shapely to count the number of points in a polygon/multipolygon. Simply use the resulting GeoJSON format (= a Python dictionary). Polygon simple: jmport fiona shape = fiona.open("simplePoly.shp") # first feature feature = shape.next() geom = feature['geometry'] print geom {'type': 'Polygon', 'coordinates': [[(1.0, 1.0), (1.0, ...


2

You can get polygon exterior and interior points coordinates this way: def extract_poly_coords(geom): if geom.type == 'Polygon': exterior_coords = geom.exterior.coords[:] interior_coords = [] for int in geom.interiors: interior_coords += i.coords[:] elif geom.type == 'MultiPolygon': ...


3

While I'm a big user of both shapely and fiona, I wouldn't go this approach. This is a task of writing an effective SQL statement. Using ogr2ogr with an SQLITE dialect, you can process this from a command line. Change directory to one before the shapefiles, so that all of the shapefiles are in one directory called data. OGR treats directories of shapefiles ...


2

Some issues in your code: you only use correctly one table as input whereas, you should use both input bufSHP and ctSHP you want to make an intersection between a list of shape and a filename with shapes.intersection(ctSHP) whereas you have to do an intersection between two shape elements See below a possibility, I choose to use Rtree to optimize, ...


1

Shapefile fields are constrained to 10 chars, and so your 'a_fieldname' gets truncated by OGR (used by Fiona) to 'a_fieldname'. There might be a Fiona bug here. Workaround in the meanwhile is to change 'a_fieldname' in your schema to 'number' or something shorter than 10.


1

Then I put every record in the rows of a pandas.DataFrame Why ? If you only want to copy the original attributes (LineString) to the new shapefile (Points), after computing the centroid, you don't need Pandas: import fiona from shapely.geometry import shape, mapping with fiona.open("polyline.shp") as input: # change only the geometry of the ...


2

With your example, polygon is a standard Python dict object that represents a GeoJSON geometry, which only uses standard data types, with no fancy geospatial properties. But you can convert polygon into a shapely geometry, as you have done with shape polygon = shapefile_record['geometry'] shape = shapely.geometry.asShape(polygon) print(shape.bounds)


5

Some solutions according to the position of an element in a list: polA = Polygon([(0,0), (3,0), (3,3), (0,3)]) polB = Polygon([(2,-1), (5,-1), (5,2), (2,2)]) polC = Polygon([(5,2), (8,2), (8,5), (5,5)]) collection = [polA, polB, polC] Iterating by index: for i in range(len(collection)-1): print collection[i], collection[i+1], ...



Top 50 recent answers are included