<div class="gmail_quote"><div>Om op sommige plekken niet afhankelijk te zijn van een PostGIS installatie had ik een simpel Python scriptje gemaakt die van RD naar WGS84 kan. Nu dacht ik slim te zijn en het scriptje uit te breiden naar de omgekeerde variant maar nu komt er totale bagger uit.</div>
<div><br></div><div><div><font face="courier new, monospace" size="1">"""</font></div><div><font face="courier new, monospace" size="1">select X(loc), Y(loc) from (select transform(setsrid(makepoint(5.96, 52.2), 4326), 28992) AS loc) as x;</font></div>
<div><font face="courier new, monospace" size="1"> x | y </font></div><div><font face="courier new, monospace" size="1">------------------+------------------</font></div><div><font face="courier new, monospace" size="1">194159.178375368 | 468142.275781605</font></div>
<div><font face="courier new, monospace" size="1">(1 row)</font></div><div><font face="courier new, monospace" size="1">"""</font></div><div><font face="courier new, monospace" size="1"> </font></div><div>
<font face="courier new, monospace" size="1">from rd import wgs84rd, rdwgs84</font></div>
<div><font face="courier new, monospace" size="1">wgs84rd(5.96, 52.2)</font></div><div><font face="courier new, monospace" size="1">(128410, 445807) # crap dus</font></div><div><font face="courier new, monospace" size="1"> </font></div>
<div><font face="courier new, monospace" size="1">rdwgs84(194159, 468142)</font></div><div><font face="courier new, monospace" size="1">(5.959997, 52.199998) # komt aardig overeen</font></div></div><div><br></div><div>Wat ik gebruik; het enige andere bij de tweede functie is dus de omdraaing van src/dst.</div>
<div><br></div><div><div><font face="courier new, monospace" size="1">from osgeo import osr, ogr</font></div><div><font face="courier new, monospace" size="1">src_string = '+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +towgs84=565.2369,50.0087,465.658,-0.406857330322398,0.350732676542563,-1.8703473836068,4.0812 +no_defs no_defs <>'</font></div>
<div><font face="courier new, monospace" size="1">dst_string = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'</font></div><div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1">src = osr.SpatialReference()</font></div>
<div><font face="courier new, monospace" size="1">src.ImportFromProj4(src_string)</font></div><div><font face="courier new, monospace" size="1">dst = osr.SpatialReference()</font></div><div><font face="courier new, monospace" size="1">dst.ImportFromProj4(dst_string)</font></div>
<div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1">def rdwgs84(x, y):</font></div><div><font face="courier new, monospace" size="1"> ogr_geom = ogr.CreateGeometryFromWkt('POINT(%d %d)' % (x, y))</font></div>
<div><font face="courier new, monospace" size="1"> ogr_geom.AssignSpatialReference(src)</font></div><div><font face="courier new, monospace" size="1"> ogr_geom.TransformTo(dst)</font></div><div><font face="courier new, monospace" size="1"><br>
</font></div><div><font face="courier new, monospace" size="1"> return (round(ogr_geom.GetX(), 6), round(ogr_geom.GetY(), 6))</font></div><div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1">def wgs84rd(lon, lat):</font></div>
<div><font face="courier new, monospace" size="1"> ogr_geom = ogr.CreateGeometryFromWkt('POINT(%d %d)' % (lon, lat))</font></div><div><font face="courier new, monospace" size="1"> ogr_geom.AssignSpatialReference(dst)</font></div>
<div><font face="courier new, monospace" size="1"> ogr_geom.TransformTo(src)</font></div><div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1"> return (int(round(ogr_geom.GetX())), int(round(ogr_geom.GetY())))</font></div>
</div><div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Wat gaat er fout?</font></div>
<span class="HOEnZb"><font color="#888888">
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Stefan</font></div></font></span></div>