Jump to content
The simFlight Network Forums

Recommended Posts

Posted

The constructor takes in an array of FsLatLonPoint that define the points (vertices) of a closed polygon. There can be any number of points. The polygon can be convex, concave or complex (having self-intersecting sides). 

Here is an example I used to test the class. I just supply hard-coded points of the outline of London: (I've removed lots of points in the middle for this example):

FsLatLonPoint[] points = new FsLatLonPoint[]
{
   new FsLatLonPoint(51.828207,-2.669643),
   new FsLatLonPoint(51.823186,-2.654353),
   new FsLatLonPoint(51.827549,-2.646808),
   new FsLatLonPoint(51.836629,-2.638694),
   // Points removed
   new FsLatLonPoint(51.796211,-2.663467),
   new FsLatLonPoint(51.801533,-2.68468),
   new FsLatLonPoint(51.812531,-2.68296),
   new FsLatLonPoint(51.828207,-2.669643)
};
FsLatLonPolygon myPolygon = new FsLatLonPolygon(points);

Normally you would get the points from a database or mapping service, so you would need to read the points and create the array of FsLatLonPoint[] in code.

If you need more specific help, let me know how you're getting the polygon point data and what format the data is in. I can then explain how to convert them to the point array.

Paul

Posted
        Dim points As FsLatLonPoint() =
        {
            New FsLatLonPoint(51.828207, -2.669643),
            New FsLatLonPoint(51.823186, -2.654353),
            New FsLatLonPoint(51.827549, -2.646808),
            New FsLatLonPoint(51.836629, -2.638694),
            New FsLatLonPoint(51.796211, -2.663467),
            New FsLatLonPoint(51.801533, -2.68468),
            New FsLatLonPoint(51.812531, -2.68296),
            New FsLatLonPoint(51.828207, -2.669643)
        }
        Dim myPolygon As FsLatLonPolygon = New FsLatLonPolygon(points)

Paul

  • 1 year later...
Posted

        FsLatLonPoint[] sector1pol = new FsLatLonPoint[]
        {
            new FsLatLonPoint(39.158189, -6.560815),
            new FsLatLonPoint(39.44173, -6.291623),
            new FsLatLonPoint(39.847553, -4.565154),
            new FsLatLonPoint(39.594515, -4.687465),
            new FsLatLonPoint(39.019832, -6.427709),
            new FsLatLonPoint(39.158189, -6.560815)
        };
        FsLatLonPolygon sector1 = new FsLatLonPolygon(sector1pol);

I have this code but fail.

Compile error CS0236 A field initializer cannot reference the non-static field, method, or property 'name'.

 

Posted

You've probably got this code at the class level, rather than inside a method.

You can't use variables (sector1pol) to initialise other variables at the class level (sector1). 

If you need these variable at the class (form) level then easiest fix is to move the initialisation into the constructor of the class. e.g. if it's a form do this:

        private FsLatLonPoint[] sector1pol;
        private FsLatLonPolygon sector1;

        public Form1()
        {
            InitializeComponent();
            this.sector1pol = new FsLatLonPoint[]
            {
                new FsLatLonPoint(39.158189, -6.560815),
                new FsLatLonPoint(39.44173, -6.291623),
                new FsLatLonPoint(39.847553, -4.565154),
                new FsLatLonPoint(39.594515, -4.687465),
                new FsLatLonPoint(39.019832, -6.427709),
                new FsLatLonPoint(39.158189, -6.560815)
            };
            this.sector1 = new FsLatLonPolygon(sector1pol);
        }

Paul

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.