[mapguide-users] Markup perpendicular

Jamo adam.jamison at portbris.com.au
Mon Jan 4 23:46:56 EST 2010


ok a little app i'm working on... it allows users to click near a road
(linear feature) and record a proposed road works site. It will markup the
GIS with propsed positions of signage and outline of site of works.

I'm still playing around witha  proof of concept.... seem to do this a lot.

The program will function as follows
1. the user digitizes a point near the centre of the proposed site of works
on the side of the road the works will be done.

function DigitizePoint()
{
parent.mapFrame.DigitizePoint(findNearest);
}
function findNearest(Point)
{
var params = new Array(
"x0", Point.X,
"y0", Point.Y,
"MAPNAME",parent.mapFrame.GetMapName(),
"SESSION",parent.mapFrame.GetSessionId());
parent.formFrame.Submit("../portbris/markup/distancebetween/Default.aspx",params,
"taskPaneFrame");
}
DigitizePoint()

2. Mapguide will figure out what road centreline is closest to the digitized
point.

//userclick is a mgPoint object created from the digitize function
        MgFeatureReader feats =
map.GetLayers().GetItem("plnCLRoads").SelectFeatures(new
MgFeatureQueryOptions());
        double shortest = -1;
        String RoadName = String.Empty;
        MgGeometry road = null;
        while (feats.ReadNext())
        {
            
            MgAgfReaderWriter agf = new MgAgfReaderWriter();
//gets geometry from feature
            MgGeometry myGeom = agf.Read(feats.GetGeometry("Geometry"));
            if (feats.IsNull("Name") == false)
                Response.Write(Math.Round(myGeom.Distance(userClick,
null),2).ToString() + "m to " + feats.GetString("Name"));
            else
                Response.Write(Math.Round(myGeom.Distance(userClick, null),
2).ToString() + "m");
            Response.Write(@"<BR />");

             if (shortest == -1)
                shortest = myGeom.Distance(userClick, null);
            else if (myGeom.Distance(userClick, null) < shortest)
            {

                road = myGeom;
                shortest = myGeom.Distance(userClick, null);
                if (feats.IsNull("Name") == false)
                {
                    RoadName = feats.GetString("Name") + " " +
feats.GetString("Type");
                    
                }
            }
        }
Response.Write("<BR/><BR/>Therefore the closest Road is <BR/>" + RoadName +
" and is " +Math.Round(shortest,2).ToString() + "m away<BR/>");


Problem: how do i get the geometry between the point and the closest road
.... the perpendicular link? would it matter if this road is curved?

First Try: create a circle at the distance found to be the distance from the
point the user clicked to the point on the closest road .... the result ends
in a circle that according to MG does not touch the road :(

MgGeometry shortGeometry(MgPoint click, MgGeometry closest, double joinDist)
    {
        MgGeometryFactory GF = new MgGeometryFactory();
        //maybe add some drafting fudge in here?
        //joinDist = joinDist + 0.001;
        MgCoordinate arcPt1 = GF.CreateCoordinateXY(click.Coordinate.X +
joinDist,  click.Coordinate.Y);

        MgCoordinate arcPt2 = GF.CreateCoordinateXY(click.Coordinate.X -
joinDist,  click.Coordinate.Y);
        MgCoordinate arcPt3 = GF.CreateCoordinateXY(click.Coordinate.X,
click.Coordinate.Y + joinDist);
        MgCoordinate arcPt4 = GF.CreateCoordinateXY(click.Coordinate.X,
click.Coordinate.Y - joinDist);
        MgArcSegment newGeom = GF.CreateArcSegment(arcPt1,arcPt2,arcPt3);
        MgArcSegment newGeom1 = GF.CreateArcSegment(arcPt2, arcPt1, arcPt4);

        MgCurveSegmentCollection myCurve = new MgCurveSegmentCollection();
        myCurve.Add(newGeom);
        myCurve.Add(newGeom1);

        MgCurvePolygon myPoly =
GF.CreateCurvePolygon(GF.CreateCurveRing(myCurve), null);

        Response.Write(closest.Touches(myPoly));

        return myPoly;
    }

3. The user is prompted with a few questions to better define the type of
works and how best to diagram it on the GIS (Yet to be finalised)

Just a fancy dialog.

4. by using the information along with the digitized point MG will now
produce a diagram markup of proposed safety signage.

Stumped until the first problem is solved, but will involve offsetting,
buffering and various geometry operations to produce the rest of the diagram

I realise i'm not showing much here... but i figure if i put the question
out to the community someone might be able to pick it too pieces and make
something of it :), is there an area for community driven snap ins for
mapguide? I would like to try and code for mapguide to keep it robust and
transferable to other users, but am finding it hard to do. some examples of
others work would be great
-- 
View this message in context: http://n2.nabble.com/Markup-perpendicular-tp4253574p4253574.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list