DotSpatial Library : MapWindow Discussion Forum
Hi all In MW6, there is a nice function in the toolbox, to Union one shapefile with another shapefile. I am using VB2008 and now want to try to get this function working programmatically, outside of MW i.e. a stand-alone application. Can anyone give me any hints as to how i implement
Union/Instersect shapefiles
Posted by:
nmb100 ()
Date: June 01, 2010 02:17AM
Hi all
In MW6, there is a nice function in the toolbox, to Union one shapefile with another shapefile. I am using VB2008 and now want to try to get this function working programmatically, outside of MW i.e. a stand-alone application. Can anyone give me any hints as to how i implement this?
Secondly, i will then use the product of two or more unioned sets and instersect each set by each other, forming a composite set of data. Any ideas?
Thanks,
Nigel
In MW6, there is a nice function in the toolbox, to Union one shapefile with another shapefile. I am using VB2008 and now want to try to get this function working programmatically, outside of MW i.e. a stand-alone application. Can anyone give me any hints as to how i implement this?
Secondly, i will then use the product of two or more unioned sets and instersect each set by each other, forming a composite set of data. Any ideas?
Thanks,
Nigel
Re: Union/Instersect shapefiles
Posted by:
Shade1974 ()
Date: June 14, 2010 09:43AM
A couple of options. If you have a reference to mwTools.dll, you can call the Execute method on the Union class, using the overload the parameters. This tool was made by KP and just glancing at the code it looks like he is doing some rounding approximations that I'm not sure should be there, but if it is working for you, then that is the easiest way to run it in your code programatically.
To get closer to the raw code, you can also access some topology methods with the FeatureSet classes. Make sure you have a "using MapWindow.Data" at the top of your code. Dimension two new "FeatureSet" classes. Open the two files you want to union. Then you should see some useful extension methods, but I think the only one that may be exposed at that level is Intersection. To do the union, you may have to use Intersection and then choose between the original features and the merged features or something.
Shade1974 (Ted Dunsford)
Here is KP's code:
To get closer to the raw code, you can also access some topology methods with the FeatureSet classes. Make sure you have a "using MapWindow.Data" at the top of your code. Dimension two new "FeatureSet" classes. Open the two files you want to union. Then you should see some useful extension methods, but I think the only one that may be exposed at that level is Intersection. To do the union, you may have to use Intersection and then choose between the original features and the merged features or something.
Shade1974 (Ted Dunsford)
Here is KP's code:
/// <summary> /// Executes the Union Opaeration tool programaticaly /// </summary> /// <param name="self">The input are feature set</param> /// <param name="other">The second input feature set</param> /// <param name="output">The output feature set</param> /// <param name="cancelProgressHandler">The progress handler</param> /// <returns></returns> public bool Execute(IFeatureSet self, IFeatureSet other, IFeatureSet output, ICancelProgressHandler cancelProgressHandler) { //Validates the input and output data if (self == null || other == null || output == null) { return false; } IFeatureSet tempOuput = self.Intersection(other, FieldJoinType.All, null); IFeatureSet tempFeatureSet = self.CombinedFields(other); int previous = 0; int max = self.Features.Count; //Take (Self-Intersect Featureset) List<IFeature> intersectList; for (int i =0 ; i< self.Features.Count ; i++) { intersectList = other.Select(self.Features.Envelope); foreach (IFeature feat in intersectList) { if (cancelProgressHandler.Cancel) return false; self.Features.Difference(feat, tempFeatureSet, FieldJoinType.LocalOnly); } if (Math.Round(i*40D/max) <= previous) continue; previous = Convert.ToInt32(Math.Round(i * 40D / max)); cancelProgressHandler.Progress("", previous, previous + TextStrings.progresscompleted); } max = other.Features.Count; //Take (Other-Intersect Featureset) for (int i = 0; i < other.Features.Count; i++) { intersectList = self.Select(other.Features.Envelope); foreach (IFeature feat in intersectList) { if (cancelProgressHandler.Cancel) return false; other.Features.Difference(feat, tempFeatureSet, FieldJoinType.LocalOnly); } if (Math.Round((i*40D/max) + 40D) <= previous) continue; previous = Convert.ToInt32(Math.Round((i * 40D / max) + 40D)); cancelProgressHandler.Progress("", previous, previous + TextStrings.progresscompleted); } max = tempFeatureSet.Features.Count; output.CopyTableSchema(tempFeatureSet); //Add the individual feature to output for (int i = 0; i < tempFeatureSet.Features.Count; i++) { output.Features.Add(tempFeatureSet.Features); if (Math.Round((i*10D/max) + 80D) <= previous) continue; previous = Convert.ToInt32(Math.Round((i * 10D / max) + 80D)); if (cancelProgressHandler.Cancel) return false; cancelProgressHandler.Progress("", previous, previous + TextStrings.progresscompleted); } max = tempOuput.Features.Count; //Add the Intersect feature to output for (int i = 0; i < tempOuput.Features.Count; i++) { output.Features.Add(tempOuput.Features); if (cancelProgressHandler.Cancel) return false; if (Math.Round((i*10D/max) + 90D) <= previous) continue; previous = Convert.ToInt32(Math.Round((i * 10D / max) + 90D)); cancelProgressHandler.Progress("", previous, previous + TextStrings.progresscompleted); } output.SaveAs(output.Filename, true); return true; }
Re: Union/Instersect shapefiles
Posted by:
nmb100 ()
Date: September 15, 2010 11:29AM
Hi Ted
I have tried incorporating jsut the simple execute code, however i keep getting the following error:
'no outgoing dirEdge found [ MapWindow.Geometries.Coordinate ]'
Do you know what this means as i am able to use the intersection method for these files using the MW4 GetIntersection method?
Thanks,
Nigel
I have tried incorporating jsut the simple execute code, however i keep getting the following error:
'no outgoing dirEdge found [ MapWindow.Geometries.Coordinate ]'
Do you know what this means as i am able to use the intersection method for these files using the MW4 GetIntersection method?
Thanks,
Nigel
Re: Union/Instersect shapefiles
Posted by:
Shade1974 ()
Date: September 15, 2010 12:42PM
It could either be a problem with the port from JTS to NTS or else a bug introduced in our code at some point when refactoring NTS into DotSpatial.Topology. If you can post a reminder of which method you are calling along with the datasets you are trying to union as an issue on the DotSpatial site, I might be able to find a bug. However, with something like this, finding the error might be difficult to do. My first step would be to attempt to perform the unions in a less tampered with version of NTS and see if it works. If it succeeds there, it is probably an easy fix and I just need to track down where the difference is. If NTS fails, then we are looking at something decidedly more painful. I suppose I could test against JTS. If JTS works, but NTS fails, then we might be able to figure out what the problem is, though I have never really used Java. It looks like I might need to start doing some Java for work, though, so this might be less of an issue shortly. In any case, this sounds like it could be a very time consuming fix, but it is probably important for a lot of people, so please post this as an issue here:
[dotspatial.codeplex.com]
Shade1974 (Ted)
Dr. Harold A Dunsford Jr.
MapWindow 6.0 & DotSpatial Initial Developer
GEI Consultants
[dotspatial.codeplex.com]
Shade1974 (Ted)
Dr. Harold A Dunsford Jr.
MapWindow 6.0 & DotSpatial Initial Developer
GEI Consultants
Sorry, you do not have permission to post/reply in this forum.


