Extensive test suite, stats, and renderings of common crs

This commit is contained in:
Karim Bahgat
2015-08-05 01:35:29 +02:00
parent 0b1ed64736
commit e24e1493ae
37 changed files with 244 additions and 42 deletions
+2 -2
View File
@@ -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:
Binary file not shown.
+2 -2
View File
@@ -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:
Binary file not shown.
+7 -2
View File
@@ -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
Binary file not shown.
BIN
View File
Binary file not shown.
+233 -36
View File
@@ -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) )
Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.