ThinkGeo.com    |     Documentation    |     Premium Support

Help with generated shapefiles

Hello there,

I have an application which preprocesses some data to be displayed as contour maps and arrays of vector arrows on my map. The contours are rendered out to bitmaps and used in a RasterLayer which is then serialized to file for loading later in our client app. All that is working fine.

The arrow shapes are created as LineShapes and added to a ShapeFileFeatureLayer in ReadWrite mode. The layer is then written out to a new shapefile, and later loaded up to a ShapeFileFeatureLayer in the client app. They stubbornly refuse to display. I’m sure I’m getting the column definitions or something similar wrong. I hope someone here can point me in the right direction.

Here is the code which generates the shapefile (it’s not complete):

Collection cols = new Collection();
cols.Add(new DbfColumn(ArrowColumnName, DbfColumnType.Character, 32, 0));
ShapeFileFeatureSource.CreateShapeFile(ShapeFileType.Multipoint, sdfFileName, cols);
ShapeFileFeatureLayer arrowFeatureLayer = new ShapeFileFeatureLayer(fileName, ShapeFileReadWriteMode.ReadWrite);
arrowFeatureLayer.Open();
arrowFeatureLayer.EditTools.BeginTransaction();
int i=0;
foreach (ArrowLine gv in gvArrows)
{
var arrow = new LineShape();
… some calculations of lengths and coordinates here …
arrow.Vertices.Add(start);
arrow.Vertices.Add(end);
arrow.Vertices.Add(barb);

                        Feature arrowFeature = new Feature((LineShape)mProjection.ConvertToExternalProjection(arrow));
                        arrowFeature.ColumnValues.Add(ArrowColumnName, ArrowColumnName + i++);

                        arrowFeatureLayer.EditTools.Add(arrow);
            }

            arrowFeatureLayer.EditTools.CommitTransaction();
            arrowFeatureLayer.Close();

This produces shapefiles which have something in them, and I load them into an overlay on my mapControl like this:
if (File.Exists(fileName))
{
ShapeFileFeatureLayer flayer = new ShapeFileFeatureLayer(fileName);
flayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(new GeoPen(GeoColor.SimpleColors.Black));
flayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
flayer.FeatureSource.Projection = MapControl.GetProjection();
this.Layers.Add(flayer);
}

[The overlay is a class derived from the ThinkGeo LayerOverlay class].

I know it’s a lot of code, but am I using the correct DbColumns and ShapeFileType etc when generating the shapefiles?

Many thanks for any assistance.

Regards,
Scott D.

Hi Soctt,

Your text format looks broken, but It looks your question is your generated shape file cannot be render in client side.

I think there are maybe two possible reasons after read your code:

  1. You build a broken shape file, please open your shape file by our GisEditor to check whether it’s broken, if that cannot be opened, please let us know your detail dll version and the detail code to generate it, some test data is helpful.

  2. Your shape file is OK, but your render code have problem. If you have a projectioned shape file, I think you only need to set correct map unit for it, it can be render correct. It looks you assign projection again when you render the shape file, please double check that and see whether you make that converted again.

Regards,

Don

Hello Don,

Thanks for the reply. Those suggestions didn’t help me, but in the end I used the ShapeFileFeatureLayer.Validate() method to discover exactly what was going wrong - it was a mismatch between the shapefile type and the constituent shape types. Once I sorted those out it worked. This method is a useful tool!

Thanks again,
Scott.

Hi Scott,

Thanks for your share, it looks I ignore the type mismatch.

I think your share should be helpful for other guy who met same issue.

Regards,

Don