Hello, In my project I have Google maps overlay and I´m loading shapefiles, I´ve noticed that the GetBoundingBox of my shapelayer changes a lot after I delete a feature.
1.- I´m deleting a feature with this code :
LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays[ProyConstants.CLayerOverlay];
ShapeFileFeatureLayer shapeFileFeatureLayer = (ShapeFileFeatureLayer)dynamicOverlay.Layers[strLayer];
shapeFileFeatureLayer.ReadWriteMode = ThinkGeo.MapSuite.Core.ShapeFileReadWriteMode.ReadWrite;
shapeFileFeatureLayer.Open();
shapeFileFeatureLayer.EditTools.BeginTransaction();
Collection<Feature> fts = shapeFileFeatureLayer.FeatureSource.GetFeaturesByColumnValue("IDOBJ", strIdObj);
Feature ftActual = fts[0];
shapeFileFeatureLayer.EditTools.Delete(ftActual.Id);
shapeFileFeatureLayer.EditTools.CommitTransaction();
shapeFileFeatureLayer.Close();
2.- After delete I change the CurrentExtent of the map to see all the features in shapelayer , but it shows me a location near Africa!
ShpLayer.Open();
int intNumObj = ShpLayer.FeatureSource.GetCount();
if (intNumObj > 0)
Map1.CurrentExtent = ShpLayer.GetBoundingBox();
ShpLayer.Close();
3.- I´ve debugged the values of ShpLayer.GetBoundingBox() before I delete the feature and after, and are very different:
Before delete : {-13037706.9243338,3857376.75995344,-9654248.29490724,1638894.80145559}
After delete : {-20026376.3937149,44927335.4271016,-20026376.3937049,44927335.4270916}
Do I making something wrong? Can you help me please?
Thanks in advance.
Julieta
Error deleting feature
Hi Julieta,
It seems there is nothing wrong in your codes. Now, I guess we can use the below codes to position the problem more easily by comparing the removal before and after.
Collection<Feature> allFeatures = worldLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns);
RectangleShape boundingBox = new RectangleShape();
if (allFeatures.Count > 0)
{
boundingBox = allFeatures[0].GetBoundingBox();
}
foreach (Feature feature in allFeatures)
{
boundingBox.ExpandToInclude(feature.GetBoundingBox());
}
if (projection != null)
{
boundingBox = projection.ConvertToExternalProjection(boundingBox);
}
Hope it helps.
Thanks,
Johnny
Hello Johnny, I´ve tested the code you´ve sent, but I have the same problem:
1.- Before delete the feature the bounding box of shape layer is {-13037706.9243338,3857376.75995344,-9654248.29490724,1638894.80145559}
2.- After delete the feature the bounding box of shape layer is {-20026376.3937149,44927335.4271016,-20026376.3937049,44927335.4270916}
3.-
RectangleShape boundingBox = new RectangleShape();
boundingBox.ExpandToInclude(allFeatures);
Map1.CurrentExtent = boundingBox;
but the boundingbox has these values {-13037706.9243388,3857376.75995844,5E-06,-5E-06}
The problem is that it seems the shapelayer lose the boundingbox after delete a feature, I´m opening the shapelayer and the bounding box always is {-20026376.3937149,44927335.4271016,-20026376.3937049,44927335.4270916}
Have you tested the same code I wrote in my first post??
Thanks in advance.
Hi Julieta,
We did test it with your codes at the first but still can recreate it. Now, what we are guessing is there might be something differences in your shape files.
In order to narrow down the issue, I think we can try to loop the features and then union them each two. I guess we might be find out some "special" features. please try the below codes:
Collection<Feature> allFeatures = worldLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns);
RectangleShape boundingBox = new RectangleShape();
if (allFeatures.Count > 0)
{
boundingBox = allFeatures[0].GetBoundingBox();
}
foreach (Feature feature in allFeatures)
{
{
boundingBox.ExpandToInclude(feature.GetBoundingBox());
Console.WriteLine(feature.GetBoundingBox().GetWellKnownText());
Console.WriteLine(boundingBox.GetWellKnownText());
}
if (projection != null)
{
boundingBox = projection.ConvertToExternalProjection(boundingBox);
}
If it is still hard to find out the issue, would you please upload your shape file here for a further debug? If the shape file extend the limitation size of uploading, please send to forumssupport@thinkgeo.com.
Thanks,
Johnny
Hello Johnny, here is a map sample, I hope you can recreate the error with the GetBoundingBox() of my shapelayer after I delete any feature.
Im using a googleoverlay and loading shapefiles.
When I load the shapefiles I set the projection :
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetWgs84ParametersString();
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
shapeFileFeatureLayer.FeatureSource.Projection = proj4;
Here is my code to delete the feature:
1.- I´m deleting a feature with this code :
LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays[ProyConstants.CLayerOverlay];
ShapeFileFeatureLayer shapeFileFeatureLayer = (ShapeFileFeatureLayer)dynamicOverlay.Layers[strLayer];
shapeFileFeatureLayer.ReadWriteMode = ThinkGeo.MapSuite.Core.ShapeFileReadWriteMode.ReadWrite;
shapeFileFeatureLayer.Open();
shapeFileFeatureLayer.EditTools.BeginTransaction();
Collection<feature> fts = shapeFileFeatureLayer.FeatureSource.GetFeaturesByColumnValue(“IDOBJ”, strIdObj);</feature>
Feature ftActual = fts[0];
shapeFileFeatureLayer.EditTools.Delete(ftActual.Id);
shapeFileFeatureLayer.EditTools.CommitTransaction();
shapeFileFeatureLayer.Close();
2.- After delete I change the CurrentExtent of the map to see all the features in shapelayer , but it shows me a location near Africa!
ShpLayer.Open();
int intNumObj = ShpLayer.FeatureSource.GetCount();
if (intNumObj > 0)
Map1.CurrentExtent = ShpLayer.GetBoundingBox();
ShpLayer.Close();
I´ve tested the code you have sent to me, but is the same behavior.
I hope you can help me,
Thanks in advance.
Map_Points.zip (1.59 KB)
Hi,
I did a further test with your codes and the data, but it seems everything is fine. Here I attached the test sample and the test video screencast.com/t/yAq8XhWS
Please make a confirmation or do some modifications to recreate it. Now I am wondering which version you are using? I test it on both the latest version and 7.0.133.0.
If it persists, please let us know.
Johnny
Hello Johnny, we area using version 6.0, I don´t know if this is a problem only in version 6. We have the upgrade to version 7 but we are not using yet that version because we have VStudio 2008. The version 7 is working with VStudio 2008 or only 2010 and framework 4 ?
Hi Julieta,
I checked the version 6.0.0.0 and Yes I can confirm it did be a bug in version 6.0 but not any more in version 7.0. Our version 7 is supported by .net framework 4, so it’s won’t work with vs2008.
Regards,
Don
Bad news.
Is there any workaround that I can use to solve this with version 6.0?? I mean, is there any other way to delete a feature?
Thanks in advance.
Hi Julieta,
Because it’s for old version 6.0, so we can just provide you a workaround.
I created a test sample, which recreated your issue, the workaround is set shapeFileFeatureLayer.FeatureSource.Projection = null; before delete and set the projection back before map refresh.
Test code write for a desktop sample, but it should works for web edition also.
private void Form1_Load(object sender, EventArgs e)
{
winformsMap1.MapUnit = GeographyUnit.Meter;
ShapeFileFeatureLayer shapeFileFeatureLayer = new ShapeFileFeatureLayer("…/…/TestData/Map_Points.shp", ShapeFileReadWriteMode.ReadWrite);
shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital1;
shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetWgs84ParametersString();
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
shapeFileFeatureLayer.FeatureSource.Projection = proj4;
shapeFileFeatureLayer.Open();
LayerOverlay overlay = new LayerOverlay();
overlay.Layers.Add(shapeFileFeatureLayer);
winformsMap1.Overlays.Add(overlay);
winformsMap1.CurrentExtent = shapeFileFeatureLayer.GetBoundingBox();
winformsMap1.Refresh();
}
private void buttonDeleteItem_Click(object sender, EventArgs e)
{
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetWgs84ParametersString();
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
ShapeFileFeatureLayer shapeFileFeatureLayer = (winformsMap1.Overlays[0] as LayerOverlay).Layers[0] as ShapeFileFeatureLayer;
// Set projection to null before delete feature
shapeFileFeatureLayer.FeatureSource.Projection = null;
shapeFileFeatureLayer.Open();
shapeFileFeatureLayer.EditTools.BeginTransaction();
Collection<Feature> fts = shapeFileFeatureLayer.FeatureSource.GetFeaturesByColumnValue(“IDOBJ”, “6”);
Feature ftActual = fts[0];
shapeFileFeatureLayer.EditTools.Delete(ftActual.Id);
shapeFileFeatureLayer.EditTools.CommitTransaction();
shapeFileFeatureLayer.Close();
// Add projection back
shapeFileFeatureLayer.FeatureSource.Projection = proj4;
shapeFileFeatureLayer.Open();
winformsMap1.CurrentExtent = shapeFileFeatureLayer.GetBoundingBox();
winformsMap1.Refresh();
}
Any question please let me know.
Regards,
Don
It works!
Thanks very much.
Hi Julieta,
That’s a good news it works for you.
Regards,
Don