Given the following NEATLINE from the results of gdalinfo on my Geospatial PDF:

  NEATLINE=POLYGON ((-1340591.5297333347 -260482.28440259479,-1340591.0579001249 1878014.4171204455,3081498.0723039531 1878014.3548907496,3081497.6538160094 -260482.78408519758,-1340591.5297333347 -260482.28440259479))

I used the following code to convert the result to EPSG:4326 coordinates

from osgeo import ogr
from osgeo import osr

x = [-1340591.5297333347,-1340591.0579001249,3081498.0723039531,3081497.6538160094,-1340591.5297333347]
y = [-260482.28440259479,1878014.4171204455,1878014.3548907496,-260482.78408519758,-260482.28440259479]

i = 0

while i < 5:

    pointX = x[i]
    pointY = y[i]

    # Spatial Reference System
    inputEPSG = 3857
    outputEPSG = 4326

    # create a geometry from coordinates
    point = ogr.Geometry(ogr.wkbPoint)
    point.AddPoint(pointX, pointY)

    # create coordinate transformation
    inSpatialRef = osr.SpatialReference()

    outSpatialRef = osr.SpatialReference()

    coordTransform = osr.CoordinateTransformation(inSpatialRef, outSpatialRef)

    # transform point

    # print point in EPSG 4326
    print point.GetY(), point.GetX()

    i += 1

This results in:

-2.33930197857 -12.0427386092
16.6318711337 -12.0427343707
16.6318705981 27.6815681634
-2.33930646355 27.681564404
-2.33930197857 -12.0427386092

It looks close to being right, but the 27 degrees longitude on lines 3 and 4 should be more around 54 degrees East.

The additional information from the gdalinfo is as follows:

GeoTransform =
  -2133343.372843582, 754.0130468353923, 3.981217275795919
  2035401.595692971, 3.953040951345574, -753.9627451388365

I assume I'm using the correct inputEPSG in my code, if not, does anyone know what I should use in its place?

I guess it is also entirely possible that the NEATLINE is incorrect.

  • 1
    Why do you think that your neatline is in EPSG:3857, and not Lambert Conformal Conical? – AndreJ Apr 21 '15 at 5:18
  • Because according to this post and the link in the first answer, when I paste the information above (PROJCS["Lambert_Conf...) in, the first result is 3857. Therefore I assumed the NEATLINE would be that projection as well. If this is wrong, how can I determine the projection of the NEATLINE? I am not the creator of this PDF, but I do use them. – js1983 Apr 21 '15 at 15:38
  • 1
    I assume that the neatline has the same projection as the PDF. The proj.4 string would be +proj=lcc +lat_1=7.66666666 +lat_2=38.3333333 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs. There does not have to be an EPSG code for it. – AndreJ Apr 21 '15 at 15:51
  • I entered that information into cs2cs and determined it was Africa_Lambert_Conformal_Conic (SRID 102024). I see now how you determined that proj.4 string. Thanks so much for your help! – js1983 Apr 21 '15 at 16:42
  • 1
    SRID 102024 is defined as +proj=lcc +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs which has slightly different parallels than your PDF. If possible, use the proj.4 string in your code. – AndreJ Apr 21 '15 at 18:10

To proof the projection string, you can load the WKT of the neatline directly into QGIS, on a tiles background:

enter image description here

The green line uses the CRS from your PDF, and the red one uses SRID 102024. Project CRS is the first one, that's why it looks like a rectangle.

By the way, I had put your PDF WKT definition into a .prj file, and ran gdalsrsinfo on it to get the proj.4 string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.