Hi,
I'm trying to create a shape file in the web edition 3.0. I get the following error on the ShapeFileFeatureLayer.CreateShapeFile line:
"Your every arguments is legal, but the arranging is wrong"
What am I doing wrong?
Thanks,
Sonja
Hi,
I'm trying to create a shape file in the web edition 3.0. I get the following error on the ShapeFileFeatureLayer.CreateShapeFile line:
"Your every arguments is legal, but the arranging is wrong"
What am I doing wrong?
Thanks,
Sonja
This is my actual code, don't know what happened when I pasted it in the first message:
DbfColumn s = new DbfColumn("TestCol", DbfColumnType.String, 1, 1);
System.Collections.ObjectModel.Collection<DbfColumn> cols = new System.Collections.ObjectModel.Collection<DbfColumn>();
cols.Add(s);
ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polygon, "C:\\test.shp", cols);
ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer("C:\\test.shp", ShapeFileReadWriteMode.ReadWrite);
layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.LightGreen, GeoColor.SimpleColors.Black);
layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
ShapeFileFeatureLayer.BuildIndexFile("C:\\test.shp");
layer.Open();
Map1.CurrentExtent = layer.FeatureSource.GetBoundingBox();
layer.Close();
Map1.StaticOverlay.Layers.Add("Test", layer);
Sonja,
First the following code
DbfColumn s = new DbfColumn("TestCol", DbfColumnType.String, 1, 1);
Should be
DbfColumn s = new DbfColumn("TestCol", DbfColumnType.String, 1, 0);
The last parameter for DbfColumn is Decimal Length, which only makes sense when the column type is double. For any other types, this should be 0.
Also the following code
System.Collections.ObjectModel.Collection cols = new System.Collections.ObjectModel.Collection();
Should be
System.Collections.ObjectModel.Collection<DbfColumn> cols = new System.Collections.ObjectModel.Collection<DbfColumn>();
As we use generic collection here.
Hope it goes well after the changes. Let us know for more queries.
Thanks
Ben..
Hi,
Thanks for the reply, after I posted the message I actually realised that the decimal length should be 0. It is working now.
Thanks very much!
Sonja
That’s great, Sonja!
Hi,
It seems that when we creating a Shape file using CreateShapeFile it Converts type of columns from Double to Integer.
Ben,
Thanks for your post,
Currenlty, in the DBF core we just support the Logical, String, Memo and Date column types, please use the string column type to instead of the Double column type and convert it to double again.
If I misunderstand anything please let me know again and if it is possible can you send a simple sample to us so that we can track your problem correctly.
Thanks,
Scott,
many thanks for your answer,
So what’s the way to convert a column type from String to Double?
thanks,
Ben
Ben,
If I am not misunderstand, I think Scott's idea is convert string to double, such as following code:
string columnValueString = "some string";
double columnValue = double.Parse(columnValueString);
Thanks,
James
Hi,
When we creating a new shapefile, how we can mention the Projection of result SahpeFile?
Regards,Ben
Ben,
We have a sample in the Code Community dedicated to that subject of saving a shapefile to a projection. Save To Projection wiki.thinkgeo.com/wiki/Map_Suite_De...Projection. I suggest you check it out. This is a sample in the Services edition but the code related to saving shapefile to projection applies to any edition.
I extracted the relevant code from the sample where I save a new shapefile to WGS84 from a shapefile originaly in Albers projection. I think that from this example, you can adapt it for your specific case.
//Projection class to go from regional Albers projection to WGS84.
Proj4Projection AlbersToWGS84_Projection = new Proj4Projection();
AlbersToWGS84_Projection.InternalProjectionParametersString = Proj4Projection.GetEsriParametersString(102008); //North America Albers Equal Area Conic
AlbersToWGS84_Projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); //WGS84
//Creates a new shapefile in WGS84 from the existing shapefile in Albers projection.
ShapeFileFeatureLayer.SaveToProjection(@"..\..\Data\albers_northamerica.shp", @"..\..\Data\wgs84_northamerica.shp", AlbersToWGS84_Projection, OverwriteMode.Overwrite);
Hi Val,
Many thanks for your quick answer.
the problem is that when we creating a new shapefile we do not know what’s the Shapefile projection is so when we want to use Proj4Projection , what should we pass as InternalProjectionParametersString ?
Ben,
Well, you have to know what the projection of your shapefile is. This information should be given to you by your data provider. Also, many times the shapefile is accompanied by PRJ file that contains the projection information information.
If you cannot get the projection information from any of those ways, please send us your shapefile and tell us where geographically it is located and we will see what we can do to help you. Thank you.