mirror of
https://github.com/wassname/PyCRS.git
synced 2026-06-27 16:10:29 +08:00
New subdivisioning of package, and added red warnings during testing
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
from . import loader
|
||||
from . import parser
|
||||
from . import webscrape
|
||||
from . import utils
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
codetype code proj4 ogcwkt esriwkt
|
||||
@@ -0,0 +1,6 @@
|
||||
from . import datums
|
||||
from . import ellipsoids
|
||||
from . import projections
|
||||
from . import units
|
||||
from . import directions
|
||||
from . import parameters
|
||||
Binary file not shown.
+17
-61
@@ -6,12 +6,12 @@
|
||||
# especially: http://fossies.org/windows/misc/saga_2.1.4_x64.zip/saga_2.1.4_x64/saga_prj.dic
|
||||
# also: http://saga.sourcearchive.com/documentation/2.0.7plus-pdfsg-2/crs__base_8cpp_source.html
|
||||
|
||||
from . import datums
|
||||
from . import ellipsoids
|
||||
from . import parameters
|
||||
from . import units
|
||||
from . import projections
|
||||
from . import webscrape
|
||||
from .elements import datums
|
||||
from .elements import ellipsoids
|
||||
from .elements import parameters
|
||||
from .elements import units
|
||||
from .elements import projections
|
||||
from . import utils
|
||||
|
||||
def from_epsg_code(code):
|
||||
"""
|
||||
@@ -26,7 +26,7 @@ def from_epsg_code(code):
|
||||
"""
|
||||
# must go online (or look up local table) to get crs details
|
||||
code = str(code)
|
||||
proj4 = webscrape.crscode_to_string("epsg", code, "proj4")
|
||||
proj4 = utils.crscode_to_string("epsg", code, "proj4")
|
||||
crs = from_proj4(proj4)
|
||||
return crs
|
||||
|
||||
@@ -43,7 +43,7 @@ def from_esri_code(code):
|
||||
"""
|
||||
# must go online (or look up local table) to get crs details
|
||||
code = str(code)
|
||||
proj4 = webscrape.crscode_to_string("esri", code, "proj4")
|
||||
proj4 = utils.crscode_to_string("esri", code, "proj4")
|
||||
crs = from_proj4(proj4)
|
||||
return crs
|
||||
|
||||
@@ -60,7 +60,7 @@ def from_sr_code(code):
|
||||
"""
|
||||
# must go online (or look up local table) to get crs details
|
||||
code = str(code)
|
||||
proj4 = webscrape.crscode_to_string("sr-org", code, "proj4")
|
||||
proj4 = utils.crscode_to_string("sr-org", code, "proj4")
|
||||
crs = from_proj4(proj4)
|
||||
return crs
|
||||
|
||||
@@ -290,40 +290,6 @@ def _from_wkt(string, wkttype, strict=False):
|
||||
item = itemclass(value)
|
||||
params.append(item)
|
||||
|
||||
## if subcontent[0] == '"Azimuth"':
|
||||
## item = parameters.Azimuth(subcontent[1])
|
||||
## params.append(item)
|
||||
## elif subcontent[0] == '"scale_factor"':
|
||||
## item = parameters.ScalingFactor(subcontent[1])
|
||||
## params.append(item)
|
||||
## elif subcontent[0] == '"latitude_of_origin"':
|
||||
## item = parameters.LatitudeOrigin(subcontent[1])
|
||||
## params.append(item)
|
||||
## elif subcontent[0] == '"standard_parallel_1"':
|
||||
## item = parameters.LatitudeFirstStndParallel(subcontent[1])
|
||||
## params.append(item)
|
||||
## elif subcontent[0] == '"standard_parallel_2"':
|
||||
## item = parameters.LatitudeSecondStndParallel(subcontent[1])
|
||||
## params.append(item)
|
||||
## elif subcontent[0] == '"Standard_Parallel_1"':
|
||||
## item = parameters.LatitudeTrueScale(subcontent[1])
|
||||
## params.append(item)
|
||||
## elif subcontent[0] == '"Central_Meridian"':
|
||||
## item = parameters.CentralMeridian(subcontent[1])
|
||||
## params.append(item)
|
||||
## elif subcontent[0] == '"Longitude_Of_Center"':
|
||||
## item = parameters.LongitudeCenter(subcontent[1])
|
||||
## params.append(item)
|
||||
## elif subcontent[0] == '"false_easting"':
|
||||
## item = parameters.FalseEasting(subcontent[1])
|
||||
## params.append(item)
|
||||
## elif subcontent[0] == '"false_northing"':
|
||||
## item = parameters.FalseNorthing(subcontent[1])
|
||||
## params.append(item)
|
||||
## elif subcontent[0] == '"satellite_height"':
|
||||
## item = parameters.SatelliteHeight(subcontent[1])
|
||||
## params.append(item)
|
||||
|
||||
# find unit
|
||||
for part in content:
|
||||
if isinstance(part, tuple):
|
||||
@@ -338,10 +304,6 @@ def _from_wkt(string, wkttype, strict=False):
|
||||
else:
|
||||
raise Exception("The specified unit name could not be found")
|
||||
|
||||
## if subcontent[0].strip('"') == "Meters":
|
||||
## unittype = parameters.UnitType(units.Meter())
|
||||
## elif subcontent[0].strip('"') == "degree":
|
||||
## unittype = parameters.UnitType(units.Degree())
|
||||
metmult = parameters.MeterMultiplier(value)
|
||||
linunit = parameters.Unit(unittype, metmult)
|
||||
|
||||
@@ -408,10 +370,6 @@ def _from_wkt(string, wkttype, strict=False):
|
||||
unittype = parameters.UnitType(unit)
|
||||
else:
|
||||
raise Exception("The specified unit name could not be found")
|
||||
## if subcontent[0].strip('"') == "Meters":
|
||||
## unittype = parameters.UnitType(units.Meter())
|
||||
## elif subcontent[0].strip('"') == "degree":
|
||||
## unittype = parameters.UnitType(units.Degree())
|
||||
metmult = parameters.MeterMultiplier(value)
|
||||
angunit = parameters.AngularUnit(unittype, metmult)
|
||||
|
||||
@@ -445,7 +403,7 @@ def from_proj4(string, strict=False):
|
||||
# parse arguments into components
|
||||
# use args to create crs
|
||||
|
||||
# SLIGTHLY MESSY STILL, CLEANUP..
|
||||
# TODO: SLIGTHLY MESSY STILL, CLEANUP..
|
||||
|
||||
params = []
|
||||
partdict = dict([part.split("=") for part in string.split()
|
||||
@@ -458,9 +416,9 @@ def from_proj4(string, strict=False):
|
||||
# first, get the default proj4 string of the +init code
|
||||
codetype, code = partdict["+init"].split(":")
|
||||
if codetype == "EPSG":
|
||||
initproj4 = webscrape.crscode_to_string("epsg", code, "proj4")
|
||||
initproj4 = utils.crscode_to_string("epsg", code, "proj4")
|
||||
elif codetype == "ESRI":
|
||||
initproj4 = webscrape.crscode_to_string("esri", code, "proj4")
|
||||
initproj4 = utils.crscode_to_string("esri", code, "proj4")
|
||||
|
||||
# make the default into param dict
|
||||
initpartdict = dict([part.split("=") for part in initproj4.split()
|
||||
@@ -512,7 +470,7 @@ def from_proj4(string, strict=False):
|
||||
coeffs = partdict["+towgs84"].split(",")
|
||||
datumshift = parameters.DatumShift(coeffs)
|
||||
|
||||
# if no datum, use ellips + towgs84 params to create the correct datum
|
||||
# TODO: if no datum, use ellips + towgs84 params to create the correct datum
|
||||
# ...??
|
||||
|
||||
# COMBINE DATUM AND ELLIPS
|
||||
@@ -587,12 +545,10 @@ def from_proj4(string, strict=False):
|
||||
# create proj param obj
|
||||
proj = parameters.Projection(projdef)
|
||||
|
||||
## # collect param objects
|
||||
## for key,val in partdict.items():
|
||||
## objclass = parameters.find(key, "proj4", strict)
|
||||
## if objclass:
|
||||
## obj = objclass(val)
|
||||
## params.append(obj)
|
||||
# Because proj4 has no element hierarchy, using automatic element find() would
|
||||
# ...would not be very effective, as that would need a try-fail approach for each
|
||||
# ...element type (parameter, projection, datum, ellipsoid, unit).
|
||||
# ...Instead load each element individually.
|
||||
|
||||
# CENTRAL MERIDIAN
|
||||
|
||||
|
||||
Binary file not shown.
@@ -4,7 +4,11 @@ import re
|
||||
def build_crs_table(savepath):
|
||||
"""
|
||||
Build crs table of all equivalent format variations by scraping spatialreference.org.
|
||||
Takes a while.
|
||||
Saves table as tab-delimited text file.
|
||||
NOTE: Might take a while.
|
||||
|
||||
Arguments:
|
||||
- *savepath*: The absolute or relative filepath to which to save the crs table, including the ".txt" extension.
|
||||
"""
|
||||
# create table
|
||||
outfile = open(savepath, "wb")
|
||||
@@ -65,6 +69,9 @@ def crscode_to_string(codetype, code, format):
|
||||
- *codetype*: "epsg", "esri", or "sr-org".
|
||||
- *code*: The code.
|
||||
- *format*: The crs format of the returned string. One of "ogcwkt", "esriwkt", or "proj4", but also several others...
|
||||
|
||||
Returns:
|
||||
- Crs string in the specified format.
|
||||
"""
|
||||
link = 'http://spatialreference.org/ref/%s/%s/%s/' %(codetype,code,format)
|
||||
result = urllib2.urlopen(link).read()
|
||||
@@ -87,7 +94,5 @@ def crscode_to_string(codetype, code, format):
|
||||
## return result
|
||||
|
||||
|
||||
##if __name__ == "__main__":
|
||||
## build_crs_table("crstable.txt")
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
import pycrs
|
||||
import traceback
|
||||
import warnings
|
||||
|
||||
|
||||
|
||||
@@ -67,15 +68,28 @@ def render_world(crs):
|
||||
# Source string generator
|
||||
def sourcestrings(format):
|
||||
# TODO: now bunch of randoms, instead add only most commonly used ones
|
||||
yield pycrs.webscrape.crscode_to_string("esri", 54030, format)
|
||||
yield pycrs.webscrape.crscode_to_string("sr-org", 7898, format)
|
||||
yield pycrs.webscrape.crscode_to_string("sr-org", 6978, format)
|
||||
yield pycrs.webscrape.crscode_to_string("epsg", 4324, format)
|
||||
yield pycrs.webscrape.crscode_to_string("sr-org", 6618, format)
|
||||
yield pycrs.webscrape.crscode_to_string("sr-org", 22, format)
|
||||
yield pycrs.webscrape.crscode_to_string("esri", 54031, format)
|
||||
yield pycrs.utils.crscode_to_string("esri", 54030, format)
|
||||
yield pycrs.utils.crscode_to_string("sr-org", 7898, format)
|
||||
yield pycrs.utils.crscode_to_string("sr-org", 6978, format)
|
||||
yield pycrs.utils.crscode_to_string("epsg", 4324, format)
|
||||
yield pycrs.utils.crscode_to_string("sr-org", 6618, format)
|
||||
yield pycrs.utils.crscode_to_string("sr-org", 22, format)
|
||||
yield pycrs.utils.crscode_to_string("esri", 54031, format)
|
||||
# add more...
|
||||
|
||||
# Misc other crs for testing
|
||||
#crs = pycrs.utils.crscode_to_string("esri", 54030, "proj4")
|
||||
#crs = pycrs.utils.crscode_to_string("sr-org", 6978, "proj4")
|
||||
#crs = pycrs.parser.from_sr_code(7898)
|
||||
#crs = pycrs.parser.from_epsg_code(4324)
|
||||
#crs = pycrs.parser.from_sr_code(6618)
|
||||
#crs = pycrs.parser.from_sr_code(22)
|
||||
#crs = pycrs.parser.from_esri_code(54031)
|
||||
#proj4 = "+proj=longlat +ellps=WGS84 +datum=WGS84"
|
||||
#proj4 = "+proj=aea +lat_1=24 +lat_2=31.5 +lat_0=24 +lon_0=-84 +x_0=400000 +y_0=0 +ellps=GRS80 +units=m +no_defs "
|
||||
#proj4 = "+proj=larr +datum=WGS84 +lon_0=0 +lat_ts=45 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs"
|
||||
#proj4 = "+proj=nsper +datum=WGS84 +ellps=WGS84 +lon_0=-60 +lat_0=40 +h=2000000000000000000000000"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -83,33 +97,23 @@ def sourcestrings(format):
|
||||
# Testing format outputs
|
||||
def testoutputs(crs):
|
||||
print("To:\n")
|
||||
try: result = crs.to_ogc_wkt()
|
||||
except: result = traceback.format_exc()
|
||||
print("ogc_wkt: %s \n" % result)
|
||||
print("ogc_wkt:\n")
|
||||
try: print(crs.to_ogc_wkt()+"\n")
|
||||
except: warnings.warn(traceback.format_exc())
|
||||
|
||||
try: result = crs.to_esri_wkt()
|
||||
except: result = traceback.format_exc()
|
||||
print("esri_wkt: %s \n" % result)
|
||||
print("esri_wkt:\n")
|
||||
try: print(crs.to_esri_wkt()+"\n")
|
||||
except: warnings.warn(traceback.format_exc())
|
||||
|
||||
try: result = crs.to_proj4()
|
||||
except: result = traceback.format_exc()
|
||||
print("proj4: %s \n" % result)
|
||||
print("proj4:\n")
|
||||
try: print(crs.to_proj4()+"\n")
|
||||
except: warnings.warn(traceback.format_exc())
|
||||
|
||||
|
||||
|
||||
|
||||
# Misc crs for testing
|
||||
#crs = pycrs.webscrape.crscode_to_string("esri", 54030, "proj4")
|
||||
#crs = pycrs.webscrape.crscode_to_string("sr-org", 6978, "proj4")
|
||||
#crs = pycrs.parser.from_sr_code(7898)
|
||||
#crs = pycrs.parser.from_epsg_code(4324)
|
||||
#crs = pycrs.parser.from_sr_code(6618)
|
||||
#crs = pycrs.parser.from_sr_code(22)
|
||||
#crs = pycrs.parser.from_esri_code(54031)
|
||||
#proj4 = "+proj=longlat +ellps=WGS84 +datum=WGS84"
|
||||
#proj4 = "+proj=aea +lat_1=24 +lat_2=31.5 +lat_0=24 +lon_0=-84 +x_0=400000 +y_0=0 +ellps=GRS80 +units=m +no_defs "
|
||||
#proj4 = "+proj=larr +datum=WGS84 +lon_0=0 +lat_ts=45 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs"
|
||||
#proj4 = "+proj=nsper +datum=WGS84 +ellps=WGS84 +lon_0=-60 +lat_0=40 +h=2000000000000000000000000"
|
||||
#############################################################################
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -130,7 +134,7 @@ for wkt in sourcestrings("ogcwkt"):
|
||||
testoutputs(crs)
|
||||
|
||||
except:
|
||||
print(traceback.format_exc()+"\n")
|
||||
warnings.warn(traceback.format_exc()+"\n")
|
||||
|
||||
#render_world(crs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user