How to draw curve (not closed) by #Map 1.0?

Topics: Algorithms, CompactFramework, Data Access, Español, General Topics, Italiano, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, Web Controls, WinForms Controls
Oct 13, 2013 at 9:26 AM
Hi Guys,

I am using #Map v1.0; Are there some methods to draw Curve (not closed)? And BTW, what is the class implementing GeoAPI.Geometry.ICurve ?
Coordinator
Oct 14, 2013 at 11:31 AM
There is not ICurve implementation in either NTS or SharpMap, sorry.
FObermaier
Oct 14, 2013 at 10:38 PM
So are there some ideas for drawing the curve by SharpMap?
Coordinator
Oct 15, 2013 at 7:09 AM
I'd use some flattening algorithm on the curve definition and transform it to a linestring.
Hth FObermaier
Editor
Oct 17, 2013 at 7:54 AM
Its a bit diffferent but I use this code to create an arc using open layers. I'm sure its easy enough to convert to sharpmap. This actually creates a pie wedge polygon shape, but it can be adapted easily enough to just give you an arc line.
point = new OpenLayers.Geometry.Point(x,y);

    distance = 100; //distance from origin point
    bearing = 180; // direction
    viewAngle = 25; // width of angle from bearing


    leftAngle = parseInt(bearing) - parseInt(viewAngle);
    rightAngle = parseInt(bearing) + parseInt(viewAngle);


    var points = new Array();
    points.push(point);


    while (leftAngle < rightAngle) {

        currentAngle = 360 + leftAngle;

        leftX = point.x + distance * Math.sin(this.toRadians(currentAngle));
        leftY = point.y + distance * Math.cos(this.toRadians(currentAngle));

        leftPoint = new OpenLayers.Geometry.Point(leftX, leftY);

        points.push(leftPoint);

        leftAngle = leftAngle + 1;
    }


    if (rightAngle < 0) {
        rightAngle = 360 + rightAngle;
    }

    rightX = Math.round(point.x + distance * Math.sin(this.toRadians(rightAngle)));
    rightY = Math.round(point.y + distance * Math.cos(this.toRadians(rightAngle)));

    var rightPoint = new OpenLayers.Geometry.Point(rightX, rightY);

    points.push(rightPoint);

    var ring = new OpenLayers.Geometry.LinearRing(points);
    var polygon = new OpenLayers.Geometry.Polygon([ring]);

    // create some attributes for the feature
    var attributes = { type: "viewshed"};

    var feature = new OpenLayers.Feature.Vector(polygon, attributes);

    return feature;
Coordinator
Oct 17, 2013 at 8:34 AM
Sometimes you don't see the woods for all the trees!

Try this:
var gsf = new NetTopologySuite.Utilities.GeometricShapeFactory();
gsv.Envelope = new GeoAPI.Geometries.Envelope(...);
var arc = gsv.CreateArc(startAngle, sweepAngle);
Oct 17, 2013 at 12:04 PM
Edited Oct 17, 2013 at 12:43 PM
Hi FObermaier, I think this might work. BTW, what are the meanings of startAngle and sweepAngle? Sorry, actually I just touched SharpMap. Would you like to give an example of implementing arc based on your codes. I have tried your 3-line codes, and there is just a closed path. Is it because of startAngle & sweepAngle, or do I miss anything?
Coordinator
Oct 17, 2013 at 12:31 PM
It is similar to http://msdn.microsoft.com/en-US/library/w2sf7st6.aspx
The rectangle is gsv.Envelope and startAngle and sweepAngle are the same as in System.Drawing.Graphics.DrawArc. It could be that you have to provide those values in radians, though.
Oct 18, 2013 at 11:45 PM
Edited Oct 19, 2013 at 4:30 AM
I found that it can draw the arc, but the problem is parameters in Envelope are not same as those in http://msdn.microsoft.com/en-US/library/w2sf7st6.aspx. What does each parameter mean in Envelope()??
        var ct_ = LayerTools.Wgs84toGoogleMercator;

        var coords1 = new[] { 0.0, 0.0 };
        coords1 = ct_.MathTransform.Transform(coords1);
        var coords2 = new[] { 100.0, 200.0  };
        coords2 = ct_.MathTransform.Transform(coords2);

        var gsf = new NetTopologySuite.Utilities.GeometricShapeFactory();
        gsf.Envelope = new GeoAPI.Geometries.Envelope(coords1[0], coords1[1], coords2[0], coords2[1]);
        var arc = gsf.CreateArc(0 , 270 * 2 * Math.PI /360 );
Coordinator
Oct 19, 2013 at 3:28 PM
the constructor of envelope takes (minx, maxx, miny, maxy). Don't you have intellisense?
Oct 20, 2013 at 11:02 PM
I see. I just didn't pay attention to that. By the way, how to deal with the Envelope whose coordinate excess valid ranges.

For example, if var coords1 = new[]{-333, 33}; var coords2 = new[]{58,-33} . Because I want to show curve on Google Mercator Coordinate system, but the coordinates like that can't be transformed into a valid GoogleMercator coordinates.
Coordinator
Oct 21, 2013 at 4:31 AM
Edited Oct 21, 2013 at 4:35 AM
You'll have to split that arc at the dateline and translate it horizontally to a range of -180 to 180.
Vertically you have to cut off everything that does not fit in the range -90 to 90.