Rasterizing a GDAL layer

EDIT: I guess I’d use qGIS python bindings: http://www.qgis.org/wiki/Python_Bindings That’s the easiest way I can think of. I remember hand rolling something before, but it’s ugly. qGIS would be easier, even if you had to make a separate Windows installation (to get python to work with it) then set up an XML-RPC server to run … Read more

Shapely point geometry in geopandas df to lat/lon columns

If you have the latest version of geopandas (0.3.0 as of writing), and the if df is a GeoDataFrame, you can use the x and y attributes on the geometry column: df[‘lon’] = df.point_object.x df[‘lat’] = df.point_object.y In general, if you have a column of shapely objects, you can also use apply to do what … Read more

How to calculate distance from a point to a line segment, on a sphere?

Here’s my own solution, based on the idea in ask Dr. Math. I’d be happy to see your feedback. Disclaimer first. This solution is correct for spheres. Earth isn’t a sphere, and the coordinates system (WGS 84) doesn’t assume it’s a sphere. So this is just an approximation, and I can’t really estimate is error. … Read more

How to convert from UTM to LatLng in python or Javascript

I ended up finding java code from IBM that solved it: http://www.ibm.com/developerworks/java/library/j-coordconvert/index.html Just for reference, here is my python implementation of the method I needed: import math def utmToLatLng(zone, easting, northing, northernHemisphere=True): if not northernHemisphere: northing = 10000000 – northing a = 6378137 e = 0.081819191 e1sq = 0.006739497 k0 = 0.9996 arc = northing … Read more

C# implementation of Google’s ‘Encoded Polyline Algorithm’

Here’s the implementation I settled on: public static string Encode(IEnumerable<GeoLocation> points) { var str = new StringBuilder(); var encodeDiff = (Action<int>)(diff => { int shifted = diff << 1; if (diff < 0) shifted = ~shifted; int rem = shifted; while (rem >= 0x20) { str.Append((char)((0x20 | (rem & 0x1f)) + 63)); rem >>= 5; … Read more

How do you know what SRID to use for a shp file?

To elaborate on synecdoche’s answer, the SRID is sometimes called an “EPSG” code. The SRID/EPSG code is a defacto short-hand for the Well-Known-Text representations of projections. You can do a quick search on the SRID table to see if you can find an exact or similar match: SELECT srid, srtext, proj4text FROM spatial_ref_sys WHERE srtext … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)