ThinkGeo.com    |     Documentation    |     Premium Support

Shapefile Projection Problem

I'm having an issue when using the reprojection system for ShapeFileFeatureSource.


 


The internal projection of the shapefile I'm trying to reproject is:


 


+proj=lcc +lat_1=34.03333333333333 +lat_2=35.46666666666667 +lat_0=33.5 +lon_0=-118 +x_0=609601.2192024384 +y_0=0 +ellps=clrk66 +datum=NAD27 +units=us-ft +no_defs


 


And I'm trying to project to WGS84:


+proj=longlat+ellps=WGS84+datum=WGS84+no_defs


 


I'm using GDAL to load the internal projection, which works well with this same code for several other shapefiles I have loaded:


 



OSGeo.OSR.SpatialReference sr = new OSGeo.OSR.SpatialReference( "" );
sr.ImportFromESRI( new string[] { prj } );
string internalProjection = "";
sr.ExportToProj4( out internalProjection );
sr.Dispose();

string externalProjection = Proj4Projection.GetEpsgParametersString( importArgs.Srid );

shapefile.Projection = new Proj4Projection( internalProjection, externalProjection );
shapefile.Projection.Open();


 


I'm importing into a PostgreSQL database, so I'm using Feature.GetWellKnownText() to grab the geometry of each feature.  However, the geometry is not at all correct and eventually returns shapes that can't be parsed by PostGIS.


 


Here's an example of the data that is returned:


MULTILINESTRING((-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98,-2.85447048245644E-164 -1.70963895410571E-98))


As you can see, this isn't even close to lat/lon values.


As a check, I looked at the values returned from Feature.GetShape() and they are the same.


 If I reproject this same file to WGS84 before importing it (using Quantum GIS), it imports as it should.


 


Any ideas?


 Thanks,

Chris


 


 


 



Chris,


Thanks for your post and explainations.
 
Just want to make sure 2 things:
1)       Did you project your data when importing to PostgreSQL? 
2)      When you get data back from PostgreSQL , did you set any projection for it?
 
If possible, could you send us your shape file data, we can find out the problem and try to write a sample for you.
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

 


This is happening during the import into PostgreSQL so the data is coming directly from a shapefile not from the database.


 


Where should I send the shapefile?


 


Thanks,


Chris



Chris, 
  
 Thanks for your response, could you contact our support(support@thinkgeo.com) to send us the data and if possible just let him forword to Yale. 
  
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale 


OK, I sent a file called 'VC_RoadInventory.zip' to support@thinkgeo.com.


 


Chris



Chris,


Thanks for your data.
 
I think this is a bug from Proj4, please try the updated DLL in attachment(replace it in C:\Windows\System32 folder). It seems that it works fine for other projections(like google projection) while it failed in this specided projecion you provided.
 
One thing is that this new DLL contains another bug , it will throw a exception when you closing, so please keep your layer unclosed.

   winformsMap1.MapUnit = GeographyUnit.DecimalDegree;

            winformsMap1.CurrentExtent = new RectangleShape(-126.4, 48.8, -67.0, 19.0);
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);


            ShapeFileFeatureLayer roadInvetoryLayer = new ShapeFileFeatureLayer(@"C:\ThinkGeo_YangYong\2008Source\DesktopEdition\Posts\DesktopPosts\Post6489\VC_RoadInventory\RoadInventory_9-2-2009.shp");
            roadInvetoryLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad1;
            roadInvetoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            string internalProjString = "+proj=lcc +lat_1=34.03333333333333 +lat_2=35.46666666666667 +lat_0=33.5 +lon_0=-118 +x_0=609601.2192024384 +y_0=0 +ellps=clrk66 +datum=NAD27 +units=us-ft +no_defs";
            string externalProjString = "+proj=longlat+ellps=WGS84+datum=WGS84+no_defs";
            Proj4Projection projection = new Proj4Projection(internalProjString, externalProjString);

            roadInvetoryLayer.RequireIndex = false;
            roadInvetoryLayer.FeatureSource.Projection = projection;

            LayerOverlay staticOverlay = new LayerOverlay();
            staticOverlay.Layers.Add("roadInvetoryLayer", roadInvetoryLayer);
            winformsMap1.Overlays.Add("LayerOverlay", staticOverlay);

            roadInvetoryLayer.Open();
            winformsMap1.CurrentExtent = roadInvetoryLayer.GetBoundingBox();
            //roadInvetoryLayer.Close();

            winformsMap1.Refresh();

 
Let me know if any more questions.
 
Thanks.
 
Yale

Chris,


Sorry for missing the attachment:).


Thanks.


Yale



1351-MapSuiteProjectionX86.zip (81.3 KB)

OK, that works.


 


Is this fix (and hopefully a fix to the exception on closing) going to be released in the next version?



Chris, 
  
 Thanks for letting us your status. This is a potential bug in Proj4 which is a opensource projection, I am not sure it will be fixed in its next version, while we will keep an eye on it. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale