Sketched more of basic API

This commit is contained in:
Karim Bahgat
2015-03-17 23:49:20 +01:00
parent a8637812b7
commit 5a46702471
5 changed files with 138 additions and 123 deletions
+49
View File
@@ -0,0 +1,49 @@
import json
#################
# USER FUNCTIONS
#################
# convenience methods for loading from different sources
def from_url(url, format=None):
# first get string from url
# ...
# then load
if format:
# load string using specified format
pass
else:
from_unknown_text(string)
def from_file(filepath):
if filepath.endswith(".prj"):
string = open(filepath, "r").read()
from_esri_wkt(string)
elif filepath.endswith((".geojson",".json")):
crsinfo = json.load(filepath)["crs"]
if crsinfo["type"] == "name":
string = crsinfo["properties"]["name"]
from_unknown_text(string)
elif crsinfo["type"] == "link":
url = crsinfo["properties"]["name"]
type = crsinfo["properties"].get("type")
from_url(url, format=type)
else: raise Exception("invalid geojson crs type: must be either name or link")
elif filepath.endswith((".tif",".tiff",".geotiff")):
pass
# ...