shp1 = realpath("../geodata/temp1-ply.shp") shp2 = realpath("../geodata/temp2-ply.shp") # output resulting GeoJSON file out_geojson_file = realpath("../geodata/result_identity.geojson") output_wkt_identity = realpath("ol3/data/ch06-04_results_identity.js") # convert our Shapefiles to GeoJSON # then to python dictionaries shp1_data = shp2_geojson_obj(shp1) shp2_data = shp2_geojson_obj(shp2) # transform our GeoJSON data into Shapely geom objects shp1_polys = create_polys(shp1_data) shp2_polys = create_polys(shp2_data) # run the difference and intersection res_difference = shp1_polys.difference(shp2_polys) res_intersection = shp1_polys.intersection(shp2_polys) # combine the difference and intersection polygons into results result_identity = create_out(res_difference, res_intersection) # export identity results to a GeoJSON out_geoj(result_identity, out_geojson_file) # write out new javascript variable with wkt geometry write_wkt(output_wkt_identity, result_identity )
# add valid geometry to list plys.append(g) # convert new polygons into a new MultiPolygon out_new_valid_multi = MultiPolygon(plys) return out_new_valid_multi if __name__ == "__main__": # input NOAA Shapefile shp = realpath("../geodata/temp-all-warn-week.shp") # output union_dissolve results as GeoJSON out_geojson_file = realpath("../geodata/ch06-03_union_dissolve.geojson") out_wkt_js = realpath("ol3/data/ch06-03_results_union.js") # input Shapefile and convert to Shapely geometries shply_geom = create_shapes(shp) # Check the Shapely geometries if they are valid if not fix them new_valid_geom = check_geom(shply_geom) # run our union with dissolve dissolve_result = cascaded_union(new_valid_geom) # output the resulting union dissolved polygons to GeoJSON file out_geoj(dissolve_result, out_geojson_file) write_wkt(out_wkt_js, dissolve_result)
# out two input test Shapefiles shp1 = realpath("../geodata/temp1-ply.shp") shp2 = realpath("../geodata/temp2-ply.shp") # output resulting GeoJSON file out_geojson_file = realpath("../geodata/result_identity.geojson") output_wkt_identity = realpath("ol3/data/ch06-04_results_identity.js") # convert our Shapefiles to GeoJSON # then to python dictionaries shp1_data = shp2_geojson_obj(shp1) shp2_data = shp2_geojson_obj(shp2) # transform our GeoJSON data into Shapely geom objects shp1_polys = create_polys(shp1_data) shp2_polys = create_polys(shp2_data) # run the difference and intersection res_difference = shp1_polys.difference(shp2_polys) res_intersection = shp1_polys.intersection(shp2_polys) # combine the difference and intersection polygons into results result_identity = create_out(res_difference, res_intersection) # export identity results to a GeoJSON out_geoj(result_identity, out_geojson_file) # write out new javascript variable with wkt geometry write_wkt(output_wkt_identity, result_identity)