I've a strange problem with the conversion of point from EPSG to GPS and vice versa.
I'm using QGis with OpenStreetMap. To do some test, I've inserted 5 marks in a random position. Then, using a python script (ogr, osr library), I've converted the point from their EPSG coordinate to GPS, and the process works great.In order to test if the opposite works, I've used the GPS value obtained and I expect the same starting EPSG coordinate, but sometimes it inverts them.
This is my very simple code:
def coordinatesTrasform(pointX, pointY, inputEPSG, outputEPSG) : point = ogr.Geometry(ogr.wkbPoint) point.AddPoint(pointX, pointY) inSpatialRef = osr.SpatialReference() inSpatialRef.ImportFromEPSG(inputEPSG) outSpatialRef = osr.SpatialReference() outSpatialRef.ImportFromEPSG(outputEPSG) coordTransform = osr.CoordinateTransformation(inSpatialRef, outSpatialRef) point.Transform(coordTransform) return {point.GetX(), point.GetY()}print "*********** TEST ***********"A_X = 1276940.5A_Y = 5529731.3B_X = 1276952.1B_Y = 5529468.1C_X = 1277206.2C_Y = 5529827.8D_X = 1277148.4D_Y = 5529596.5E_X = 1277154.0E_Y = 5529435.7 points = {(A_X, A_Y, "A"), (B_X, B_Y, "B"), (C_X, C_Y, "C"), (D_X, D_Y, "D"), (E_X, E_Y, "E")}for p in points: print p[2] print "EPSG: (%.2f, %.2f)" % (p[0], p[1]) GPS_E = GPS_N = EPSG_X = EPSG_Y = 0 GPS_E, GPS_N = coordinatesTrasform(p[0], p[1], 3857, 4326) print "EPSG --> GPS: (%fE, %fN)" % (GPS_E, GPS_N) EPSG_X, EPSG_Y = coordinatesTrasform(GPS_E, GPS_N, 4326, 3857) print "GPS --> EPSG: (%.2f, %.2f)" % (EPSG_X, EPSG_Y) print ""print "Manual GPS coordinates of the D point:"E = 11.472819N = 44.413113EPSG_X, EPSG_Y = coordinatesTrasform(E, N, 4326, 3857)print "GPS --> EPSG: (%.2f, %.2f)" % (EPSG_X, EPSG_Y)This is the output:
*********** TEST ***********BEPSG: (1276952.10, 5529468.10)EPSG --> GPS: (11.471056E, 44.412289N)GPS --> EPSG: (5529468.10, 1276952.10)EEPSG: (1277154.00, 5529435.70)EPSG --> GPS: (11.472870E, 44.412081N)GPS --> EPSG: (1277154.00, 5529435.70)DEPSG: (1277148.40, 5529596.50)EPSG --> GPS: (11.472819E, 44.413113N)GPS --> EPSG: (1277148.40, 5529596.50)CEPSG: (1277206.20, 5529827.80)EPSG --> GPS: (11.473339E, 44.414597N)GPS --> EPSG: (1277206.20, 5529827.80)AEPSG: (1276940.50, 5529731.30)EPSG --> GPS: (11.470952E, 44.413978N)GPS --> EPSG: (5529731.30, 1276940.50)Manual GPS coordinates of the D pointGPS --> EPSG: (5529596.54, 1277148.37)As you can see, the point A and B show different vale for input and output (the EPSG code of the conversion from GPS has the coordinates inverted), but for example, the D point result correct. This is the first odd thing.Then, if I insert manually the GPS coordinates of the D point, than the epsg coordinates are inverted! The second add thing!!
I'm going crazy!! I'm not able to explain this behaviour.
ps. this is the screen of the qgis map:
أكثر...
I'm using QGis with OpenStreetMap. To do some test, I've inserted 5 marks in a random position. Then, using a python script (ogr, osr library), I've converted the point from their EPSG coordinate to GPS, and the process works great.In order to test if the opposite works, I've used the GPS value obtained and I expect the same starting EPSG coordinate, but sometimes it inverts them.
This is my very simple code:
def coordinatesTrasform(pointX, pointY, inputEPSG, outputEPSG) : point = ogr.Geometry(ogr.wkbPoint) point.AddPoint(pointX, pointY) inSpatialRef = osr.SpatialReference() inSpatialRef.ImportFromEPSG(inputEPSG) outSpatialRef = osr.SpatialReference() outSpatialRef.ImportFromEPSG(outputEPSG) coordTransform = osr.CoordinateTransformation(inSpatialRef, outSpatialRef) point.Transform(coordTransform) return {point.GetX(), point.GetY()}print "*********** TEST ***********"A_X = 1276940.5A_Y = 5529731.3B_X = 1276952.1B_Y = 5529468.1C_X = 1277206.2C_Y = 5529827.8D_X = 1277148.4D_Y = 5529596.5E_X = 1277154.0E_Y = 5529435.7 points = {(A_X, A_Y, "A"), (B_X, B_Y, "B"), (C_X, C_Y, "C"), (D_X, D_Y, "D"), (E_X, E_Y, "E")}for p in points: print p[2] print "EPSG: (%.2f, %.2f)" % (p[0], p[1]) GPS_E = GPS_N = EPSG_X = EPSG_Y = 0 GPS_E, GPS_N = coordinatesTrasform(p[0], p[1], 3857, 4326) print "EPSG --> GPS: (%fE, %fN)" % (GPS_E, GPS_N) EPSG_X, EPSG_Y = coordinatesTrasform(GPS_E, GPS_N, 4326, 3857) print "GPS --> EPSG: (%.2f, %.2f)" % (EPSG_X, EPSG_Y) print ""print "Manual GPS coordinates of the D point:"E = 11.472819N = 44.413113EPSG_X, EPSG_Y = coordinatesTrasform(E, N, 4326, 3857)print "GPS --> EPSG: (%.2f, %.2f)" % (EPSG_X, EPSG_Y)This is the output:
*********** TEST ***********BEPSG: (1276952.10, 5529468.10)EPSG --> GPS: (11.471056E, 44.412289N)GPS --> EPSG: (5529468.10, 1276952.10)EEPSG: (1277154.00, 5529435.70)EPSG --> GPS: (11.472870E, 44.412081N)GPS --> EPSG: (1277154.00, 5529435.70)DEPSG: (1277148.40, 5529596.50)EPSG --> GPS: (11.472819E, 44.413113N)GPS --> EPSG: (1277148.40, 5529596.50)CEPSG: (1277206.20, 5529827.80)EPSG --> GPS: (11.473339E, 44.414597N)GPS --> EPSG: (1277206.20, 5529827.80)AEPSG: (1276940.50, 5529731.30)EPSG --> GPS: (11.470952E, 44.413978N)GPS --> EPSG: (5529731.30, 1276940.50)Manual GPS coordinates of the D pointGPS --> EPSG: (5529596.54, 1277148.37)As you can see, the point A and B show different vale for input and output (the EPSG code of the conversion from GPS has the coordinates inverted), but for example, the D point result correct. This is the first odd thing.Then, if I insert manually the GPS coordinates of the D point, than the epsg coordinates are inverted! The second add thing!!
I'm going crazy!! I'm not able to explain this behaviour.
ps. this is the screen of the qgis map:
أكثر...