How to get Geometry image to display?

louwholouwho USMember ✭✭✭

I am fairly new to this, so bear with me. I created a cross-platform, PCL, and loaded an image from disk (which worked fine)...

      Xamarin.Forms.Image image = new Xamarin.Forms.Image
        {
            Source = new FileImageSource
            {
                File = Device.OnPlatform(iOS: "mapit.png",
                          Android: "mapit.png",
                          WinPhone: "Assets/mapit.png")
            },
            HorizontalOptions = LayoutOptions.Center,
            VerticalOptions = LayoutOptions.CenterAndExpand
        };

I added NetTopologySuite to the PCL (I do not know what else to use, to both create the polygon, and gets its area). I want to create a polygon, and display it, (instead of using an image file from disk). This is the code that created the polygon...

        //next line is necessary, else will not run without a Service
        GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices();
        //NetTopologySuite.Geometries.GeometryFactory gfactory = new NetTopologySuite.Geometries.GeometryFactory;
        GeoAPI.Geometries.IGeometryFactory gfactory = NetTopologySuite.Geometries.GeometryFactory.Fixed;
        WKTReader greader = new WKTReader(gfactory);
        IGeometry polygon1 = greader.Read("POLYGON((0 0, 0 10, 20 10, 20 20, 25 20, 25 10, 40 10, 40 0, 0 0))");
        double area1 = 0;
        area1 = polygon1.Area;
        Xamarin.Forms.Image img = (Xamarin.Forms.Image)polygon1;

It builds ok, but errors out with "System.InvalidCastException: Specified cast is not valid.", on that last line above. In a previous WPF solution, using DBGeometry (instead of using NetTopologySuite), things worked fine, but when that code is not usable here as there is not yet any Spatial in Xamarin, WPF, etc. When trying to use some of that code I kept getting "reference to 'Marshalbyrefobject' claims it is in mscorlib, but it cannot be found"...I guess the mscorlib is different for cross-platform (?).

So, how do I get the image of the polygon to display?

Tagged:
Sign In or Register to comment.