diff --git a/pycrs/elements/datums.py b/pycrs/elements/datums.py index 0d3cbf4..dabc031 100644 --- a/pycrs/elements/datums.py +++ b/pycrs/elements/datums.py @@ -2,7 +2,7 @@ def find(datumname, crstype, strict=False): if not strict: - datumname = datumname.lower() + datumname = datumname.lower().replace(" ","_") for itemname,item in globals().items(): if itemname.startswith("_"): continue @@ -10,7 +10,7 @@ def find(datumname, crstype, strict=False): if hasattr(item, crstype): itemname = getattr(item, crstype) if not strict: - itemname = itemname.lower() + itemname = itemname.lower().replace(" ","_") if datumname == itemname: return item except: diff --git a/pycrs/elements/datums.pyc b/pycrs/elements/datums.pyc index e74ee25..0549e30 100644 Binary files a/pycrs/elements/datums.pyc and b/pycrs/elements/datums.pyc differ diff --git a/pycrs/elements/ellipsoids.py b/pycrs/elements/ellipsoids.py index da1d133..a32dd2a 100644 --- a/pycrs/elements/ellipsoids.py +++ b/pycrs/elements/ellipsoids.py @@ -2,7 +2,7 @@ def find(ellipsname, crstype, strict=False): if not strict: - ellipsname = ellipsname.lower() + ellipsname = ellipsname.lower().replace(" ","_") for itemname,item in globals().items(): if itemname.startswith("_"): continue @@ -10,7 +10,7 @@ def find(ellipsname, crstype, strict=False): if hasattr(item, crstype): itemname = getattr(item, crstype) if not strict: - itemname = itemname.lower() + itemname = itemname.lower().replace(" ","_") if ellipsname == itemname: return item except: diff --git a/pycrs/elements/ellipsoids.pyc b/pycrs/elements/ellipsoids.pyc index acd0826..634f957 100644 Binary files a/pycrs/elements/ellipsoids.pyc and b/pycrs/elements/ellipsoids.pyc differ diff --git a/pycrs/elements/projections.py b/pycrs/elements/projections.py index a24c1cb..00bd547 100644 --- a/pycrs/elements/projections.py +++ b/pycrs/elements/projections.py @@ -2,7 +2,7 @@ def find(projname, crstype, strict=False): if not strict: - projname = projname.lower() + projname = projname.lower().replace(" ","_") for itemname,item in globals().items(): if itemname.startswith("_"): continue @@ -10,7 +10,7 @@ def find(projname, crstype, strict=False): if hasattr(item, crstype): itemname = getattr(item, crstype) if not strict: - itemname = itemname.lower() + itemname = itemname.lower().replace(" ","_") if projname == itemname: return item except: @@ -92,6 +92,11 @@ class Orthographic: ogc_wkt = "Orthographic" esri_wkt = "Orthographic" +class Stereographic: + proj4 = "stere" + ogc_wkt = "Stereographic" + esri_wkt = "Stereographic" + class PolarStereographic: proj4 = "stere" ogc_wkt = "Polar_Stereographic" # could also be just stereographic diff --git a/pycrs/elements/projections.pyc b/pycrs/elements/projections.pyc index 8b7c509..1bcfe5e 100644 Binary files a/pycrs/elements/projections.pyc and b/pycrs/elements/projections.pyc differ diff --git a/pycrs/parser.pyc b/pycrs/parser.pyc index eeef61f..a1e0452 100644 Binary files a/pycrs/parser.pyc and b/pycrs/parser.pyc differ diff --git a/tester.py b/tester.py index bad2fa1..6006d3b 100644 --- a/tester.py +++ b/tester.py @@ -1,12 +1,12 @@ import pycrs import traceback -import warnings +import logging ########################### # Drawing routine for testing -def render_world(crs): +def render_world(crs, savename): import urllib2 import json import pygeoj @@ -31,8 +31,8 @@ def render_world(crs): [zip(*pyproj.transform(fromproj, toproj, zip(*ring)[0], zip(*ring)[1])) for ring in poly] for poly in feat.geometry.coordinates] + feat.geometry.update_bbox() # important to clear away old bbox # get zoom area - # NOTE: PYGEOJ data.bbox doesnt update.........FIX! data.add_all_bboxes() data.update_bbox() bbox = data.bbox @@ -45,12 +45,12 @@ def render_world(crs): ## bbox = (min(xmins), min(ymins), max(xmaxs), max(ymaxs)) # set up drawing - c = pyagg.Canvas(600,600) + c = pyagg.Canvas(1000,1000) c.geographic_space() c.zoom_bbox(*bbox) c.zoom_out(1.3) - # draw + # draw countries for feat in data: try: c.draw_geojson(feat.geometry, fillcolor=tuple(random.randrange(255) for _ in range(3)), @@ -58,7 +58,13 @@ def render_world(crs): except: # NOTE: feat.__geo_interface__ is one level too high maybe?? print("unable to draw?", feat.geometry) - c.view() + + # draw text of the proj4 string used + c.percent_space() + c.draw_text(crs.to_proj4(), (50,10)) + + # save + c.save("testrenders/"+savename+".png") @@ -67,14 +73,102 @@ def render_world(crs): # Source string generator def sourcestrings(format): - # TODO: now bunch of randoms, instead add only most commonly used ones + # commonly used projections on global scale + # from http://www.remotesensing.org/geotiff/proj_list/ + + ##Albers Equal-Area Conic + yield pycrs.utils.crscode_to_string("sr-org", 62, format) + ##Azimuthal Equidistant + yield pycrs.utils.crscode_to_string("esri", 54032, format) + ##Cassini-Soldner + # ...ignore, too specific + ##Cylindrical Equal Area + yield pycrs.utils.crscode_to_string("sr-org", 8287, format) + ##Eckert IV + yield pycrs.utils.crscode_to_string("esri", 54012, format) + ##Eckert VI + yield pycrs.utils.crscode_to_string("esri", 54010, format) + ##Equidistant Conic + yield pycrs.utils.crscode_to_string("esri", 54027, format) + ##Equidistant Cylindrical + yield pycrs.utils.crscode_to_string("epsg", 3786, format) + ##Equirectangular + yield pycrs.utils.crscode_to_string("sr-org", 8270, format) + ##Gauss-Kruger + # ...not found??? + ##Gall Stereographic + yield pycrs.utils.crscode_to_string("esri", 54016, format) + ##GEOS - Geostationary Satellite View + yield pycrs.utils.crscode_to_string("sr-org", 81, format) + ##Gnomonic + # ...not found + ##Hotine Oblique Mercator + yield pycrs.utils.crscode_to_string("esri", 54025, format) + ##Krovak + yield pycrs.utils.crscode_to_string("sr-org", 6688, format) + ##Laborde Oblique Mercator + # ...not found # yield pycrs.utils.crscode_to_string("epsg", 9813, format) + ##Lambert Azimuthal Equal Area + yield pycrs.utils.crscode_to_string("sr-org", 28, format) + ##Lambert Conic Conformal (1SP) + # ...not found + ##Lambert Conic Conformal (2SP) + yield pycrs.utils.crscode_to_string("sr-org", 29, format) # yield pycrs.utils.crscode_to_string("epsg", 9802, format) + ##Lambert Conic Conformal (2SP Belgium) + # ...ignore, too specific + ##Lambert Cylindrical Equal Area + yield pycrs.utils.crscode_to_string("sr-org", 8287, format) + ##Mercator (1SP) + yield pycrs.utils.crscode_to_string("sr-org", 16, format) + ##Mercator (2SP) + yield pycrs.utils.crscode_to_string("sr-org", 7094, format) + ##Miller Cylindrical + yield pycrs.utils.crscode_to_string("esri", 54003, format) + ##Mollweide + yield pycrs.utils.crscode_to_string("esri", 54009, format) + ##New Zealand Map Grid + # ...ignore, too specific + ##Oblique Mercator + yield pycrs.utils.crscode_to_string("esri", 54025, format) + ##Oblique Stereographic + yield pycrs.utils.crscode_to_string("epsg", 3844, format) + ##Orthographic + yield pycrs.utils.crscode_to_string("sr-org", 6980, format) + ##Polar Stereographic + yield pycrs.utils.crscode_to_string("sr-org", 8243, format) + ##Polyconic + yield pycrs.utils.crscode_to_string("esri", 54021, format) + ##Robinson yield pycrs.utils.crscode_to_string("esri", 54030, format) - yield pycrs.utils.crscode_to_string("sr-org", 7898, format) + ##Rosenmund Oblique Mercator + # ...not found + ##Sinusoidal + yield pycrs.utils.crscode_to_string("sr-org", 6965, format) + ##Swiss Oblique Cylindrical + # ...ignore, too specific + ##Swiss Oblique Mercator + # ...ignore, too specific + ##Stereographic + yield pycrs.utils.crscode_to_string("sr-org", 6711, format) + ##Transverse Mercator + # ...not found??? + ##Transverse Mercator (Modified Alaska) + # ...ignore, too specific + ##Transverse Mercator (South Oriented) + # ...ignore, too specific + ##Tunisia Mining Grid + # ...ignore, too specific + ##VanDerGrinten 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) + + # bunch of randoms + #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 @@ -96,18 +190,27 @@ def sourcestrings(format): # Testing format outputs def testoutputs(crs): - print("To:\n") print("ogc_wkt:\n") - try: print(crs.to_ogc_wkt()+"\n") - except: warnings.warn(traceback.format_exc()) + try: + print(crs.to_ogc_wkt()+"\n") + global ogcwkt_outputs + ogcwkt_outputs += 1 + except: logging.warn(traceback.format_exc()) print("esri_wkt:\n") - try: print(crs.to_esri_wkt()+"\n") - except: warnings.warn(traceback.format_exc()) + try: + print(crs.to_esri_wkt()+"\n") + global esriwkt_outputs + esriwkt_outputs += 1 + except: logging.warn(traceback.format_exc()) print("proj4:\n") - try: print(crs.to_proj4()+"\n") - except: warnings.warn(traceback.format_exc()) + try: + print(crs.to_proj4()+"\n") + global proj4_outputs + proj4_outputs += 1 + except: logging.warn(traceback.format_exc()) + @@ -122,7 +225,16 @@ def testoutputs(crs): print("--------") print("Testing from ogc wkt:") print("") + +totals = 0 +loaded = 0 +ogcwkt_outputs = 0 +esriwkt_outputs = 0 +proj4_outputs = 0 +renders = 0 + for wkt in sourcestrings("ogcwkt"): + totals += 1 # test parsing try: @@ -130,13 +242,31 @@ for wkt in sourcestrings("ogcwkt"): print(wkt) print("") crs = pycrs.parser.from_ogc_wkt(wkt) + loaded += 1 + # test outputs + print("To:\n") testoutputs(crs) - except: - warnings.warn(traceback.format_exc()+"\n") + # test render + try: + print("Rendering...") + savename = "%i_from_ogcwkt" % totals + render_world(crs, savename) + renders += 1 + print("Successully rendered! \n") + except: + logging.warn(traceback.format_exc()+"\n") -#render_world(crs) + except: + logging.warn(traceback.format_exc()+"\n") + +print("Summary results:") +print(" Loaded: %f%%" % (loaded/float(totals)*100) ) +print(" Outputs (OGC WKT): %f%%" % (ogcwkt_outputs/float(totals)*100) ) +print(" Outputs (ESRI WKT): %f%%" % (esriwkt_outputs/float(totals)*100) ) +print(" Outputs (Proj4): %f%%" % (proj4_outputs/float(totals)*100) ) +print(" Renders: %f%%" % (renders/float(totals)*100) ) @@ -146,14 +276,48 @@ for wkt in sourcestrings("ogcwkt"): print("--------") print("Testing from proj4:") print("") -proj4 = "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs" -print(proj4) -print("") -crs = pycrs.parser.from_proj4(proj4) -testoutputs(crs) +totals = 0 +loaded = 0 +ogcwkt_outputs = 0 +esriwkt_outputs = 0 +proj4_outputs = 0 +renders = 0 -#render_world(crs) +for proj4 in sourcestrings("proj4"): + totals += 1 + + # test parsing + try: + print("From:\n") + print(proj4) + print("") + crs = pycrs.parser.from_proj4(proj4) + loaded += 1 + + # test outputs + print("To:\n") + testoutputs(crs) + + # test render + try: + print("Rendering...") + savename = "%i_from_proj4" % totals + render_world(crs, savename) + renders += 1 + print("Successully rendered! \n") + except: + logging.warn(traceback.format_exc()+"\n") + + except: + logging.warn(traceback.format_exc()+"\n") + +print("Summary results:") +print(" Loaded: %f%%" % (loaded/float(totals)*100) ) +print(" Outputs (OGC WKT): %f%%" % (ogcwkt_outputs/float(totals)*100) ) +print(" Outputs (ESRI WKT): %f%%" % (esriwkt_outputs/float(totals)*100) ) +print(" Outputs (Proj4): %f%%" % (proj4_outputs/float(totals)*100) ) +print(" Renders: %f%%" % (renders/float(totals)*100) ) @@ -161,17 +325,50 @@ testoutputs(crs) ########################### # From ESRI WKT/PRJ FILE print("--------") -print("Testing from esri prj file:") -print("") -wkt = open("testfiles/natearth.prj").read() -print(wkt) +print("Testing from esri wkt:") print("") -crs = pycrs.loader.from_file("testfiles/natearth.prj") -testoutputs(crs) - -#render_world(crs) +totals = 0 +loaded = 0 +ogcwkt_outputs = 0 +esriwkt_outputs = 0 +proj4_outputs = 0 +renders = 0 +for wkt in sourcestrings("esriwkt"): + totals += 1 + + # test parsing + try: + print("From:\n") + print(wkt) + print("") + crs = pycrs.parser.from_esri_wkt(wkt) + loaded += 1 + + # test outputs + print("To:\n") + testoutputs(crs) + + # test render + try: + print("Rendering...") + savename = "%i_from_esriwkt" % totals + render_world(crs, savename) + renders += 1 + print("Successully rendered! \n") + except: + logging.warn(traceback.format_exc()+"\n") + + except: + logging.warn(traceback.format_exc()+"\n") + +print("Summary results:") +print(" Loaded: %f%%" % (loaded/float(totals)*100) ) +print(" Outputs (OGC WKT): %f%%" % (ogcwkt_outputs/float(totals)*100) ) +print(" Outputs (ESRI WKT): %f%%" % (esriwkt_outputs/float(totals)*100) ) +print(" Outputs (Proj4): %f%%" % (proj4_outputs/float(totals)*100) ) +print(" Renders: %f%%" % (renders/float(totals)*100) ) diff --git a/testrenders/15_from_esriwkt.png b/testrenders/15_from_esriwkt.png new file mode 100644 index 0000000..4a5c32d Binary files /dev/null and b/testrenders/15_from_esriwkt.png differ diff --git a/testrenders/15_from_ogcwkt.png b/testrenders/15_from_ogcwkt.png new file mode 100644 index 0000000..0a3bc3c Binary files /dev/null and b/testrenders/15_from_ogcwkt.png differ diff --git a/testrenders/15_from_proj4.png b/testrenders/15_from_proj4.png new file mode 100644 index 0000000..54d0115 Binary files /dev/null and b/testrenders/15_from_proj4.png differ diff --git a/testrenders/16_from_esriwkt.png b/testrenders/16_from_esriwkt.png new file mode 100644 index 0000000..20bcc8c Binary files /dev/null and b/testrenders/16_from_esriwkt.png differ diff --git a/testrenders/16_from_proj4.png b/testrenders/16_from_proj4.png new file mode 100644 index 0000000..3f664ce Binary files /dev/null and b/testrenders/16_from_proj4.png differ diff --git a/testrenders/18_from_esriwkt.png b/testrenders/18_from_esriwkt.png new file mode 100644 index 0000000..8cc45bb Binary files /dev/null and b/testrenders/18_from_esriwkt.png differ diff --git a/testrenders/18_from_ogcwkt.png b/testrenders/18_from_ogcwkt.png new file mode 100644 index 0000000..251a690 Binary files /dev/null and b/testrenders/18_from_ogcwkt.png differ diff --git a/testrenders/18_from_proj4.png b/testrenders/18_from_proj4.png new file mode 100644 index 0000000..bbd4927 Binary files /dev/null and b/testrenders/18_from_proj4.png differ diff --git a/testrenders/19_from_esriwkt.png b/testrenders/19_from_esriwkt.png new file mode 100644 index 0000000..2cdaf86 Binary files /dev/null and b/testrenders/19_from_esriwkt.png differ diff --git a/testrenders/19_from_ogcwkt.png b/testrenders/19_from_ogcwkt.png new file mode 100644 index 0000000..c2821b9 Binary files /dev/null and b/testrenders/19_from_ogcwkt.png differ diff --git a/testrenders/19_from_proj4.png b/testrenders/19_from_proj4.png new file mode 100644 index 0000000..fda9092 Binary files /dev/null and b/testrenders/19_from_proj4.png differ diff --git a/testrenders/23_from_esriwkt.png b/testrenders/23_from_esriwkt.png new file mode 100644 index 0000000..bfe209b Binary files /dev/null and b/testrenders/23_from_esriwkt.png differ diff --git a/testrenders/23_from_proj4.png b/testrenders/23_from_proj4.png new file mode 100644 index 0000000..dc26291 Binary files /dev/null and b/testrenders/23_from_proj4.png differ diff --git a/testrenders/25_from_esriwkt.png b/testrenders/25_from_esriwkt.png new file mode 100644 index 0000000..27498aa Binary files /dev/null and b/testrenders/25_from_esriwkt.png differ diff --git a/testrenders/25_from_ogcwkt.png b/testrenders/25_from_ogcwkt.png new file mode 100644 index 0000000..b914462 Binary files /dev/null and b/testrenders/25_from_ogcwkt.png differ diff --git a/testrenders/25_from_proj4.png b/testrenders/25_from_proj4.png new file mode 100644 index 0000000..2ceb3d3 Binary files /dev/null and b/testrenders/25_from_proj4.png differ diff --git a/testrenders/26_from_proj4.png b/testrenders/26_from_proj4.png new file mode 100644 index 0000000..8768743 Binary files /dev/null and b/testrenders/26_from_proj4.png differ diff --git a/testrenders/28_from_esriwkt.png b/testrenders/28_from_esriwkt.png new file mode 100644 index 0000000..cc252bc Binary files /dev/null and b/testrenders/28_from_esriwkt.png differ diff --git a/testrenders/28_from_proj4.png b/testrenders/28_from_proj4.png new file mode 100644 index 0000000..bb17dec Binary files /dev/null and b/testrenders/28_from_proj4.png differ diff --git a/testrenders/3_from_esriwkt.png b/testrenders/3_from_esriwkt.png new file mode 100644 index 0000000..be99f7f Binary files /dev/null and b/testrenders/3_from_esriwkt.png differ diff --git a/testrenders/3_from_ogcwkt.png b/testrenders/3_from_ogcwkt.png new file mode 100644 index 0000000..21f3485 Binary files /dev/null and b/testrenders/3_from_ogcwkt.png differ diff --git a/testrenders/3_from_proj4.png b/testrenders/3_from_proj4.png new file mode 100644 index 0000000..ab8219b Binary files /dev/null and b/testrenders/3_from_proj4.png differ diff --git a/testrenders/6_from_esriwkt.png b/testrenders/6_from_esriwkt.png new file mode 100644 index 0000000..dd9e84e Binary files /dev/null and b/testrenders/6_from_esriwkt.png differ diff --git a/testrenders/6_from_ogcwkt.png b/testrenders/6_from_ogcwkt.png new file mode 100644 index 0000000..bc973ff Binary files /dev/null and b/testrenders/6_from_ogcwkt.png differ diff --git a/testrenders/8_from_esriwkt.png b/testrenders/8_from_esriwkt.png new file mode 100644 index 0000000..05695bf Binary files /dev/null and b/testrenders/8_from_esriwkt.png differ diff --git a/testrenders/9_from_esriwkt.png b/testrenders/9_from_esriwkt.png new file mode 100644 index 0000000..268145c Binary files /dev/null and b/testrenders/9_from_esriwkt.png differ diff --git a/testrenders/9_from_ogcwkt.png b/testrenders/9_from_ogcwkt.png new file mode 100644 index 0000000..6f9a7a8 Binary files /dev/null and b/testrenders/9_from_ogcwkt.png differ diff --git a/testrenders/9_from_proj4.png b/testrenders/9_from_proj4.png new file mode 100644 index 0000000..231bb46 Binary files /dev/null and b/testrenders/9_from_proj4.png differ diff --git a/testrenders/Thumbs.db b/testrenders/Thumbs.db new file mode 100644 index 0000000..1170c95 Binary files /dev/null and b/testrenders/Thumbs.db differ