Hello,
I am developing a GIS Application, I have the following doubts and need your suggestion.
1. How to convert the Map 3D co-ordinate system that is set in the current dwg to equivalent SRID.
This is what I get from the Map3D
WKT: PROJCS["WGS84.PseudoMercator",GEOGCS["LL84",DATUM["WGS84",SPHEROID["WGS84",6378137.000,298.25722293]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Popular Visualisation Pseudo Mercator"],PARAMETER["false_easting",0.000],PARAMETER["false_northing",0.000],PARAMETER["central_meridian",0.00000000000000],UNIT["Meter",1.00000000000000]]
When I triy to get the SRID for this WKT in postGIS using the following query
select * from spatial_ref_sys WHERE srtext LIKE '%PROJCS["WGS84.PseudoMercator",GEOGCS["LL84",DATUM["WGS84",SPHEROID["WGS84",6378137.000,298.25722293]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Popular Visualisation Pseudo Mercator"],PARAMETER["false_easting",0.000],PARAMETER["false_northing",0.000],PARAMETER["central_meridian",0.00000000000000],UNIT["Meter",1.00000000000000]]%';
I am not gettting any result in PostGIS,
All I want is,
Get the current CS that is present in the current dwg and get equvalent SRID in PostGIS so I can save the SRID specific to a geometry along with that.
2. Also I need to know what is the best practice for a simple GIS application.
Should we convert all the geometry to one SRID (When storing in postGIS DB) if so what SRID is commonly used so the data can be shown back in Map3D, ESRI, Google maps and open maps without issues.
Please Advice.
Hello,
For the first question, AutoCAD MAP can give you the SRID corresponding to the spatial reference of the drawing. Some time ago, I played with that and got this function that could help you:
public int GetCRS() { int csEPSG = -1; try { Autodesk.Gis.Map.Platform.AcMapMap map = Autodesk.Gis.Map.Platform.AcMapMap.GetCurrentMap(); string wkt = map.GetMapSRS(); //map.CoordinateSystem.SridCode //map.CoordinateSystem.EpsgCode if (string.IsNullOrEmpty(wkt)) { //No coordinate system is assigned } else { OSGeo.MapGuide.MgCoordinateSystemFactory factory = new OSGeo.MapGuide.MgCoordinateSystemFactory(); //Get assigned CS. code, such as "UTM83-12" string csCode = factory.ConvertWktToCoordinateSystemCode(wkt); csEPSG = factory.ConvertWktToEpsgCode(wkt); } } catch //(System.Exception ex) { csEPSG = - 1; } return csEPSG; }
For the second question, I'm not any kind of guru on this, but I think that the best is having the information in the most common spatial reference (EPSG:4326 will be known on all platforms for sure) but in all of the outputs the spatial reference will be the same, the best option will be to transform the data to it (avoiding to reproject for viewing).
Hope this helps!
Thanks Mate,
Sorry for the deplayed reply.
I solved the first issue.
Regarding the second one,
Here is what I am trying to do.
PGIS DB stores all geometry in EPSG:4326 irrespective of whats the local project is.
1. PGIS DB > AutoCAD
- if Projection is EPSG:4326 then no transformation the objects gets drawn
- if projection is different from EPSG:4326 then the objects get transformed from EPSG:4326 to the local projection.
Is that correct.
I have one more questions,
Now I can bring data from PGIS and display in AutoCAD,
Lets say if users create additional objects such as lines, points, etc
How can that be converted to Geomtry in Map3d in EPSG:4326 (convert if different) projection to be updated back to the PGIS DB.
Just a code snippet would be helpfull.
Thanks again for your help.!!
You are lucky!
I have a method that is supposed to transform brtween different SRIDs (I think it worked fine lat time I checked it):
public double[] TransformPoint(double[] src, int srcSRID, int targetSRID) { if (this.srcSRID == srcSRID && this.targetSRID == targetSRID) return TransformPoint(src); double[] retVal = new double[src.Length]; OSGeo.MapGuide.MgCoordinateSystemFactory coordSysFactory = new OSGeo.MapGuide.MgCoordinateSystemFactory(); MgCoordinateSystem srcCS = coordSysFactory.Create(coordSysFactory.ConvertEpsgCodeToWkt(srcSRID)); MgCoordinateSystem targetCS = coordSysFactory.Create(coordSysFactory.ConvertEpsgCodeToWkt(targetSRID)); MgCoordinateSystemTransform CoordTrans = coordSysFactory.GetTransform(srcCS, targetCS); double laZ = 0; if (src.Length >= 3) laZ = src[2]; MgCoordinate output = CoordTrans.Transform(src[0], src[1], laZ); retVal[0] = output.X; retVal[1] = output.Y; if (retVal.Length > 2) retVal[2] = output.Z; return retVal; }
"src" is an array of doubles with 2 (lon/x, lat/y) or 3 (lon/x, lat/y, z) doubles.
Give it a try!