Can I put a NetTopologySuite polygon in a "Universal windows" xaml element?

249 views
Skip to first unread message

Louwho

unread,
Mar 7, 2016, 10:52:10 AM3/7/16
to NetTopologySuite
I was pointed to this group, by someone in SpatiaLite (I cannot fund a NuGet source for SpatiaLite\Universal windows).  Is this group still active, I do not see any activity recently?

I want to display a Polygon created using NetTopologySuite, in an xaml file, grid...

I was pointed to NetTopologySuite, so I added GeoAPi, and NetTopologySuite (Nuget), to a new project, and then looked for examples.  You can imagine, that there is not much out there yet.  I did find this...http://gis.stackexchange.com/questions/21318/how-to-convert-lines-to-polygons-using-nettopologysuite.  Now I am not a full time C# developer, nor am I all that familiar with GIS, so, I am going at this in a trial by fire approach.  I wanted to see if I could create a polygon, and then display it in the XAML grid.

<Page
    x:Class="nts2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:nts2"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid x:Name="g1"  Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <!--<Polygon x:Name="PPPolygon" Stroke="Black" Fill="Red"/> -->
    </Grid>
</Page>

This is the code behind...

GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices();


IGeometryFactory geometryFactory = new GeometryFactory();

List<IGeometry> lines = new List<IGeometry>();

WKTReader rdr = new WKTReader(geometryFactory);


lines.Add(rdr.Read("LINESTRING (0 0, 10 0)"));

lines.Add(rdr.Read("LINESTRING (10 0, 10 10)"));

lines.Add(rdr.Read("LINESTRING (10 10, 0 10)"));

lines.Add(rdr.Read("LINESTRING (0 10, 0 0)"));


Polygonizer polygonizer = new Polygonizer();

polygonizer.Add(lines);

IList<IGeometry> polys = new System.Collections.Generic.List<IGeometry>(polygonizer.GetPolygons());


This is where I am trying to display the polygon, in the phone xaml file.  The first error message I got was "cannot convert from systems.collections.generic.ilist<GeoAPI.geomertys.igeomerty> to windows.ui.xaml.uielement". As you can see, I have tried various different things, and have not been successful.  There must be some kind of explicit cast (which I am obviously not familiar with), otherwise why use NetTopologySuite if you cannot display it in the app?


//g1.Children.Add(polygonizer.GetPolygons();

//Polygon p1 = polygonizer.GetPolygons().Cast<Polygon>

//PPPolygon.Points = lines.Cast < Windows.UI.Xaml.Shapes.Polygon.PointsProperty >

PPPolygon.Points = polygonizer.GetPolygons().Cast<PointCollection>;


 

FObermaier

unread,
Mar 8, 2016, 3:15:32 AM3/8/16
to NetTopologySuite
Yes, you can:
Unfortunatly there is no nuget-package for this project, you have to compile it yourself.

For its usage, please see:

Hth FObermaier

Lou Elston

unread,
Mar 8, 2016, 11:09:02 AM3/8/16
to nettopol...@googlegroups.com
As I previously stated, I am fairly new to this. I am not looking for someone to do all my work, but I do need more information.  How to you include in Visual Studio project?   I am unclear on if this is an additional thing to add to my existing solution\project (Already have the GeoAPi and NetTopologySuite), or, if this is to replace them.  Does it work in Windows Universal?  Is there any code example that you can point me to (create polygon, use it in XAML code)?  Thanks

--
You received this message because you are subscribed to a topic in the Google Groups "NetTopologySuite" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nettopologysuite/pwY5NZUidBc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nettopologysui...@googlegroups.com.
To post to this group, send email to nettopol...@googlegroups.com.
Visit this group at https://groups.google.com/group/nettopologysuite.
For more options, visit https://groups.google.com/d/optout.

Lou Elston

unread,
Mar 9, 2016, 6:13:50 PM3/9/16
to nettopol...@googlegroups.com
can anyone help me here?

FObermaier

unread,
Mar 10, 2016, 2:23:26 AM3/10/16
to NetTopologySuite
The easiest way is to add the files to your project.

I noticed that you will have to make modifications to the code, especially namespace modifications:
The project was made for WPF Geometry and StreamGeometry. Those are not the geometries you are needing. Some of the methods are not available either, so you will have to find a work around or maybe you don't need them at all.

Namespace modifications include:
System.Windows.Media -> Windows.UI.Xaml.Media
System.Windows -> Windows.Foundation

You definately need:
- WpfPathGeometryWriter.cs
- IPointTransformation.cs
- IdentityPointTransformation.cs
- IPointToPathGeometryFactory.cs
- PointToPathGeometryFactory.cs

You need to define PATH_GEOMETRY as a compile time constant.

I don't have an environment at hand where I can help you any further (Windows7) so you are on your own.

Felix

Am Montag, 7. März 2016 16:52:10 UTC+1 schrieb Louwho:
Reply all
Reply to author
Forward
0 new messages