-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Improved overlap calculations for larger geometries - Added a geometry simplification tool to reduce number of vertices
- Loading branch information
Showing
9 changed files
with
136 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
__author__ = 'Samapriya Roy' | ||
__email__ = '[email protected]' | ||
__version__ = '0.2.6' | ||
__version__ = '0.2.7' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
"PSOrthoTile": [ | ||
"analytic", | ||
"udm", | ||
"udm2", | ||
"analytic_xml" | ||
], | ||
"PSScene3Band": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import visvalingamwyatt as vw | ||
import json | ||
|
||
|
||
# get coordinates list depth | ||
def list_depth(dic, level=1): | ||
counter = 0 | ||
str_dic = str(dic) | ||
if "[[[[" in str_dic: | ||
counter += 1 | ||
return(counter) | ||
|
||
|
||
def geosimple(inp,output,num): | ||
try: | ||
import fiona | ||
shape = fiona.open(inp) | ||
with open(inp) as aoi: | ||
aoi_resp = json.load(aoi) | ||
if list_depth(aoi_resp['features'][0]['geometry']['coordinates'])==0: | ||
print('Number of current vertices '+str(len(aoi_resp['features'][0]['geometry']['coordinates'][0]))) | ||
elif list_depth(aoi_resp['features'][0]['geometry']['coordinates'])==1: | ||
print('Number of current vertices '+str(len(aoi_resp['features'][0]['geometry']['coordinates'][0][0]))) | ||
else: | ||
print('Please check GeoJSON: Could not parse coordinates') | ||
with fiona.Env(): | ||
with fiona.open(inp, 'r') as src: | ||
with fiona.open(output, 'w', schema=src.schema, driver=src.driver, crs=src.crs) as sink: | ||
for f in src: | ||
sink.write(vw.simplify_feature(f, number=num)) | ||
print('Write Completed to: '+str(output)) | ||
except ImportError: | ||
with open(inp) as aoi: | ||
aoi_resp = json.load(aoi) | ||
if list_depth(aoi_resp['features'][0]['geometry']['coordinates'])==0: | ||
aoi_geom = aoi_resp['features'][0]['geometry']['coordinates'] | ||
print('Number of current vertices '+str(len(aoi_resp['features'][0]['geometry']['coordinates'][0]))) | ||
elif list_depth(aoi_resp['features'][0]['geometry']['coordinates'])==1: | ||
aoi_geom = aoi_resp['features'][0]['geometry']['coordinates'][0] | ||
print('Number of current vertices '+str(len(aoi_resp['features'][0]['geometry']['coordinates'][0][0]))) | ||
else: | ||
print('Please check GeoJSON: Could not parse coordinates') | ||
ft = { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [] | ||
}, | ||
"properties": { | ||
"vertex_count": num | ||
} | ||
} | ||
ft['geometry']['coordinates']=aoi_geom | ||
#returns a copy of the feature, simplified (using number of vertices) | ||
b= vw.simplify_feature(ft, number=num) | ||
ft['geometry']['coordinates']=b['geometry']['coordinates'] | ||
with open(output, 'w') as g: | ||
json.dump(ft, g) | ||
print('Write Completed to: '+str(output)) | ||
#geomsimple(inp=r'C:\Users\samapriya\Downloads\vertex.geojson',output=r'C:\Users\samapriya\Downloads\v2.geojson',num=5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters