Hi,
when i load a agregated spatial table to MsSql2008FeatureLayer i am getting the below exception, could you please tell me where i am going wrong.
Exception:There’re some invalid geometry instance in table not valid. About invalid geometry please have a look at msdn.microsoft.com/en-us/library/bb933890.aspx website. To solve this problem, we provide MakeAllGeometryValid function to make the invalid geometry to be valid, because of the function updating your data, you need to backup your data before using this function.
steps i have done
1)loaded US county shapefiles to sql server 2012 using Shape2Sql tool(Geography,srid=4326,no spatial index).
2)done aggregation on counties by states and stored in new table.
3)trying to show new table on wpf map.
i have tried various methods like MakeAllGeometriesValid in code and MakeValid in sql but they didnt worked.
thanks.
Invalid geometry instance Exception
Hi lalitya,
It seems the steps are right but I am not sure if you set the srid when using the MsSql2008FeatureLayer in WPF map? Like this:
MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "States", "recid"); sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
sql2008Layer.Srid = 4326;
If it persists, would you mind to export some issue records from SQL Server and then send to us?
Regards,
Johnny
Hi Johnny,
I set the srid in code also.
please take the sample shapefiles if it might help you.
CountyShapes.zip (902 KB)
Hi, lalitya
We test the latest version based on your data under sql server 2012, but we doesn’t recreate it on our end.
Here is our test video as follow: screencast.com/t/sYrX9N8orCq , would you please try again on your end?
If the issue persists, would you please provide us the sql script with data and the test projection?
Thanks,
Johnny
Hi Johnny,
County spatial data is working, but states aggregated data is not loading to map.
I have done geography union on states and it not loading.
insert
into
StatesGeom(
Name
,geom)
select
STATE_NAME,geography::UnionAggregate(geom)
from
CountyGeom
group
by
STATE_NAME
Thanks.
Hi Lalitya,
We debug into this and found out the issue is happened to the “UnionAggregate”. After union those geom, we can get some invalid geom in the new records. you can run the below T-SQL scripts in the new table.
select * from
(select t.STIsValid() as result,ID from
(select geometry::STGeomFromWKB(geom.STAsBinary(),4326) as t,ID
from CountyShapesGeography) as s) as tt where tt.result=‘0’
So, we need to find other way to union those geometrys without any invalid geometry.
Another solution is using Map Suite Core library to union them. Partial codes like the below:
MsSql2008FeatureLayer sqlLayer = new MsSql2008FeatureLayer(connectionstr, “CountyShapesGeography”, “ID”);
Collection<Feature> features = sqlLayer.QueryTools.GetFeaturesByColumnValue(“STATE_NAME”, “Alaska”);
MultipolygonShape AlaskaShape = AreaBaseShape.Union(features);
If anything confused, please feel free to let us know.
Thanks,
Johnny
Hi Johnny,
Thanks for the above query,issue is because of invalid boundaries in shapefile.
i have solved it using the below conversion
GEOGRAPHY::STGeomFromText(geometry::STGeomFromWKB(geography::UnionAggregate(geom).STAsBinary(),4326).MakeValid().STAsText(),4326)
as
geom
Thanks for your help.
Hi Lalitya,
Good to hear it helps.
Any questions, please feel free to let us know.
Thanks,
Johnny