mirror of
https://github.com/wassname/PyCRS.git
synced 2026-06-27 16:10:29 +08:00
Sketched more of basic API
This commit is contained in:
@@ -0,0 +1 @@
|
||||
codetype code proj4 ogcwkt esriwkt
|
||||
@@ -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
|
||||
# ...
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+88
-123
@@ -1,123 +1,88 @@
|
||||
|
||||
import json
|
||||
|
||||
|
||||
#################
|
||||
# USER FUNCTIONS
|
||||
#################
|
||||
|
||||
|
||||
# parse from text strings
|
||||
# possible use module: https://github.com/rockdoc/grabbag/wiki/CRS-WKT-Parser
|
||||
# also note some paramter descriptions: http://www.geoapi.org/3.0/javadoc/org/opengis/referencing/doc-files/WKT.html
|
||||
# and see gdal source code: http://gis.stackexchange.com/questions/129764/how-are-esri-wkt-projections-different-from-ogc-wkt-projections
|
||||
|
||||
def from_epsg_code(string):
|
||||
# must go online (or look up local table) to get crs details
|
||||
pass
|
||||
|
||||
def from_esri_code(string):
|
||||
# must go online (or look up local table) to get crs details
|
||||
pass
|
||||
|
||||
def from_sr_code(string):
|
||||
# must go online (or look up local table) to get crs details
|
||||
pass
|
||||
|
||||
def from_esri_wkt(string):
|
||||
# parse arguments into components
|
||||
# use args to create crs
|
||||
pass
|
||||
|
||||
def from_ogc_wkt(string):
|
||||
# parse arguments into components
|
||||
# use args to create crs
|
||||
pass
|
||||
|
||||
def from_unknown_wkt(string):
|
||||
# detect if ogc wkt or esri wkt
|
||||
# TIPS: esri wkt datums all use "D_" before the datum name
|
||||
# then load with appropriate function
|
||||
pass
|
||||
|
||||
def from_proj4(string):
|
||||
# parse arguments into components
|
||||
# use args to create crs
|
||||
pass
|
||||
|
||||
def from_ogc_urn(string):
|
||||
# hmmm, seems like ogc urn could be anything incl online link, epsg, etc...
|
||||
# if necessary, must go online (or lookup local table) to get details
|
||||
# maybe test which of these and run their function?
|
||||
pass
|
||||
|
||||
def from_unknown_text(text):
|
||||
# detect type and load with appropriate function
|
||||
|
||||
if string.startswith("urn:"):
|
||||
from_ogc_urn(string)
|
||||
|
||||
elif string.startswith("+proj="):
|
||||
from_proj4(string)
|
||||
|
||||
elif string.startswith("PROJCS["):
|
||||
from_unknown_wkt(string)
|
||||
|
||||
elif string.startswith("EPSG:"):
|
||||
from_epsg_code(string)
|
||||
|
||||
elif string.startswith("ESRI:"):
|
||||
from_esri_code(string)
|
||||
|
||||
elif string.startswith("SR-ORG:"):
|
||||
from_sr_code(string)
|
||||
|
||||
else: raise Exception("Could not detect which type of crs")
|
||||
|
||||
def from_geotiff_params(**params):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
# 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
|
||||
# ...
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# parse from text strings
|
||||
# possible use module: https://github.com/rockdoc/grabbag/wiki/CRS-WKT-Parser
|
||||
# also note some paramter descriptions: http://www.geoapi.org/3.0/javadoc/org/opengis/referencing/doc-files/WKT.html
|
||||
# and see gdal source code: http://gis.stackexchange.com/questions/129764/how-are-esri-wkt-projections-different-from-ogc-wkt-projections
|
||||
|
||||
def from_epsg_code(string):
|
||||
# must go online (or look up local table) to get crs details
|
||||
pass
|
||||
|
||||
def from_esri_code(string):
|
||||
# must go online (or look up local table) to get crs details
|
||||
pass
|
||||
|
||||
def from_sr_code(string):
|
||||
# must go online (or look up local table) to get crs details
|
||||
pass
|
||||
|
||||
def from_esri_wkt(string):
|
||||
# parse arguments into components
|
||||
# use args to create crs
|
||||
pass
|
||||
|
||||
def from_ogc_wkt(string):
|
||||
# parse arguments into components
|
||||
# use args to create crs
|
||||
pass
|
||||
|
||||
def from_unknown_wkt(string):
|
||||
# detect if ogc wkt or esri wkt
|
||||
# TIPS: esri wkt datums all use "D_" before the datum name
|
||||
# then load with appropriate function
|
||||
pass
|
||||
|
||||
def from_proj4(string):
|
||||
# parse arguments into components
|
||||
# use args to create crs
|
||||
pass
|
||||
|
||||
def from_ogc_urn(string):
|
||||
# hmmm, seems like ogc urn could be anything incl online link, epsg, etc...
|
||||
# if necessary, must go online (or lookup local table) to get details
|
||||
# maybe test which of these and run their function?
|
||||
# examples urn:ogc:def:crs:OGC:1.3:CRS1
|
||||
# or with EPSG instead of OGC
|
||||
|
||||
# If OGC, 1.3 is pdf version, and after that is a name from list below
|
||||
# as found in pdf: "Definition identifier URNs in OGC namespace"
|
||||
# OGC crs definitions
|
||||
# URN | CRS name | Definition reference
|
||||
# urn:ogc:def:crs:OGC:1.3:CRS1 Map CS B.2 in OGC 06-042
|
||||
# urn:ogc:def:crs:OGC:1.3:CRS84 WGS 84 longitude-latitude B.3 in OGC 06-042
|
||||
# urn:ogc:def:crs:OGC:1.3:CRS83 NAD83 longitude-latitude B.4 in OGC 06-042
|
||||
# urn:ogc:def:crs:OGC:1.3:CRS27 NAD27 longitude-latitude B.5 in OGC 06-042
|
||||
# urn:ogc:def:crs:OGC:1.3:CRS88 NAVD 88 B.6 in OGC 06-042
|
||||
# urn:ogc:def:crs:OGC:1.3:AUTO42001:99:8888 Auto universal transverse mercator B.7 in OGC 06-042
|
||||
# urn:ogc:def:crs:OGC:1.3:AUTO42002:99:8888 Auto transverse mercator B.8 in OGC 06-042
|
||||
# urn:ogc:def:crs:OGC:1.3:AUTO42003:99:8888 Auto orthographic B.9 in OGC 06-042
|
||||
# urn:ogc:def:crs:OGC:1.3:AUTO42004:99:8888 Auto equirectangular B.10 in OGC 06-042
|
||||
# urn:ogc:def:crs:OGC:1.3:AUTO42005:99 Auto Mollweide B.11 in OGC 06-042
|
||||
|
||||
pass
|
||||
|
||||
def from_unknown_text(text):
|
||||
# detect type and load with appropriate function
|
||||
|
||||
if string.startswith("urn:"):
|
||||
from_ogc_urn(string)
|
||||
|
||||
elif string.startswith("+proj="):
|
||||
from_proj4(string)
|
||||
|
||||
elif string.startswith("PROJCS["):
|
||||
from_unknown_wkt(string)
|
||||
|
||||
elif string.startswith("EPSG:"):
|
||||
from_epsg_code(string)
|
||||
|
||||
elif string.startswith("ESRI:"):
|
||||
from_esri_code(string)
|
||||
|
||||
elif string.startswith("SR-ORG:"):
|
||||
from_sr_code(string)
|
||||
|
||||
else: raise Exception("Could not detect which type of crs")
|
||||
|
||||
def from_geotiff_params(**params):
|
||||
pass
|
||||
Reference in New Issue
Block a user