From 0ebf57e79874686ec7b4de2b8381c29c8595962e Mon Sep 17 00:00:00 2001 From: Karim Bahgat Date: Tue, 4 Aug 2015 16:46:47 +0200 Subject: [PATCH] New subdivisioning of package, and added red warnings during testing --- pycrs/__init__.py | 2 +- pycrs/__init__.pyc | Bin 269 -> 265 bytes pycrs/crstable.txt | 1 - pycrs/elements/__init__.py | 6 +++ pycrs/elements/__init__.pyc | Bin 0 -> 408 bytes pycrs/{ => elements}/datums.py | 0 pycrs/{ => elements}/datums.pyc | Bin pycrs/{ => elements}/directions.py | 0 pycrs/{ => elements}/directions.pyc | Bin pycrs/{ => elements}/ellipsoids.py | 0 pycrs/{ => elements}/ellipsoids.pyc | Bin pycrs/{ => elements}/parameters.py | 0 pycrs/{ => elements}/parameters.pyc | Bin pycrs/{ => elements}/projections.py | 0 pycrs/{ => elements}/projections.pyc | Bin pycrs/{ => elements}/units.py | 0 pycrs/{ => elements}/units.pyc | Bin pycrs/parser.py | 78 ++++++--------------------- pycrs/parser.pyc | Bin 15345 -> 15294 bytes pycrs/{webscrape.py => utils.py} | 11 ++-- pycrs/{webscrape.pyc => utils.pyc} | Bin 2357 -> 2590 bytes tester.py | 62 +++++++++++---------- 22 files changed, 65 insertions(+), 95 deletions(-) delete mode 100644 pycrs/crstable.txt create mode 100644 pycrs/elements/__init__.py create mode 100644 pycrs/elements/__init__.pyc rename pycrs/{ => elements}/datums.py (100%) rename pycrs/{ => elements}/datums.pyc (100%) rename pycrs/{ => elements}/directions.py (100%) rename pycrs/{ => elements}/directions.pyc (100%) rename pycrs/{ => elements}/ellipsoids.py (100%) rename pycrs/{ => elements}/ellipsoids.pyc (100%) rename pycrs/{ => elements}/parameters.py (100%) rename pycrs/{ => elements}/parameters.pyc (100%) rename pycrs/{ => elements}/projections.py (100%) rename pycrs/{ => elements}/projections.pyc (100%) rename pycrs/{ => elements}/units.py (100%) rename pycrs/{ => elements}/units.pyc (100%) rename pycrs/{webscrape.py => utils.py} (92%) rename pycrs/{webscrape.pyc => utils.pyc} (66%) diff --git a/pycrs/__init__.py b/pycrs/__init__.py index de33765..4e0ec82 100644 --- a/pycrs/__init__.py +++ b/pycrs/__init__.py @@ -1,4 +1,4 @@ from . import loader from . import parser -from . import webscrape +from . import utils diff --git a/pycrs/__init__.pyc b/pycrs/__init__.pyc index 65e754e04709eefd01119fd50a713f8f499347e8..ee49d64b898f5ca769a8df3711e477aaa95d582f 100644 GIT binary patch delta 28 jcmeBW>SSVP{>;nOe)_;f_G(U61_p-GlFXdqiT!l|d-4e} delta 32 ncmeBV>SbbQ{>;m@w0put_G(^E1_p-m)TH9%qQrvKiQRPooCpeT diff --git a/pycrs/crstable.txt b/pycrs/crstable.txt deleted file mode 100644 index d18a776..0000000 --- a/pycrs/crstable.txt +++ /dev/null @@ -1 +0,0 @@ -codetype code proj4 ogcwkt esriwkt diff --git a/pycrs/elements/__init__.py b/pycrs/elements/__init__.py new file mode 100644 index 0000000..a17b4e7 --- /dev/null +++ b/pycrs/elements/__init__.py @@ -0,0 +1,6 @@ +from . import datums +from . import ellipsoids +from . import projections +from . import units +from . import directions +from . import parameters diff --git a/pycrs/elements/__init__.pyc b/pycrs/elements/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..28e8a4ac3e61d85bd130ce5929f04c6961357a38 GIT binary patch literal 408 zcmY+A&q~BF5XL9{x66v)GkEH0A3#Kf74#(1WiKI6YMVpWqzO%W=-YYsaeM)1k_v0W z_l4hNGLt0#x!&D=f1P?*M~3SY$`5F$fq@1v3^)TuoJG!nXNmL3Iq*Dj5xD?fBrYSD zz{|u{cadZ;^9u5JQfk3%2@Gi``O4b vc=4jb>--_!mqT+DZs{>YYMJ)hR^k2HcJG!zuf8{Sn6-SMzMk%O!~W(k?1+7ZCbPos+|iV7>mlRbi|Dnq~Iz_?muwR zIv83+&?YFNUBAF(+vo?>og41ta_)KVIS=<<&Uf>DbAdd|yyjs`29Xc(C!0gYB-|EIdiv xo8%{0HpL_!vQ0^z|6?;7=PiCaP_C4Z%T=$=QcjYREay1XXQxg}o-lur{{tf)VI}|o delta 522 zcmZvYJxc>Y5Qg7La+lm!5(xoKV?+*9*jSj02DK5av^cwf2KAz%m}qj6#xFDoHj3;& zP_PwAZzHC(7O}81t@s0UZ$xY?X7-t#X9s5Qn;%Uz{AuY<=Tfb00$VCdD#(kX1(c%j zVhk~O8iR(44o^pmP%@YeW|P@uwwNvEICGpi!JJ@DUcT*E8h~bHxv^4T+OD)q)EOjO z4A^N>g=5c<(mu4iL^tjAp$Cm#+QTD;LU*E&-zP)7=6l6c{(!n-*2$(G;R724FN709 zeG-0HEIDc2xKkLxsyz_zL?fJT)m>FT%3)a_v^B7Q$dm&!8c`Et=G27 zwY8P9l!QHgG5sEr12VD$D?!Q7Ut}cz#9XdNw%tH-1JR`*$#-zWL5c_}7U^0{6!(-V H^9#;5jx}h+ diff --git a/pycrs/webscrape.py b/pycrs/utils.py similarity index 92% rename from pycrs/webscrape.py rename to pycrs/utils.py index 6b8e7e6..f27a6eb 100644 --- a/pycrs/webscrape.py +++ b/pycrs/utils.py @@ -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") diff --git a/pycrs/webscrape.pyc b/pycrs/utils.pyc similarity index 66% rename from pycrs/webscrape.pyc rename to pycrs/utils.pyc index 79bc85609324610154fd19198690a10203f6ecb7..497b14421f05f6374adfc902cecf2c14c74e951c 100644 GIT binary patch delta 368 zcmY+9u};G<6h)ID(h%qXLP%ZEqaz|&x}b;w2^ayXbn50LPGjLFRs526>jwancmAQO z*qQkShJFM);>BXA2m4vq=icj&qxWNX=cntxe68G}n08+Bbk@OD1M$K|n&1>c7YZh$4}7DvF5_`XMf`4^)O1N|Z$irVcumWzA#s=t$Pz z&aYz+^u`N!YZOxHL-)+~^}v0#$LmiQ>`Ma;Io4I7B6A7ghB6gaZIUQVn40lKWP*O5 jmDQAC2zt|Lww&L*-u^X(Dwj6vK(D-DOF!8=wXgmFI8}3+ delta 157 zcmbOyvQ>zU`7W)&QD2= iFUgNDE-A{)OSb_E7PA2f2F}UzICU`$|IaDMXaN8b4=~~Y diff --git a/tester.py b/tester.py index 66ad539..bad2fa1 100644 --- a/tester.py +++ b/tester.py @@ -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)