Appendix B. Working with Polygons

In some cases, you may need more than just one point to represent your entities. For example, if you have a call center territory and you need to model it spatially, you cannot do that using a point, since it contains a set of points that make up the territory shape. If you need to define more than a single point location in a data source, you can create a polygon data source .

In MapPoint Web Service, like point data sources, polygon data sources include spatial and non-spatial entities. A polygon data source allows you to define one or more regions on a map. You can then use these regions to find spatial relations to other polygons (such as rectangles), point data sources, addresses, and specific geographic locations. For example, you may define the delivery area for a store as a polygon. You can then look up a customer’s address and determine whether it is within the delivery area. Polygons can be as simple as a single ring of connected points, or may be complex, with an external ring containing numerous internal rings that define areas not included in the polygon.

What Is a Polygon?

Polygons are defined by an ordered series of latitude/longitude points (vertices) with an implied connection between consecutive vertices and between the last and first vertex. A polygon data source can contain one or more polygons, and a single polygon data source can contain up to 500 vertices. Each polygon consists of a single external ring and may include multiple internal rings. When you create a polygon, you must first define the external ring. Figure B-1 shows the external ring of a polygon with 6 vertices and the implied edges drawn between each

In addition to the external ring, a polygon can contain one or more internal rings. Like the external ring, internal rings are defined by an ordered list of vertices, and no two implied edges may intersect. Therefore, each internal ring must be entirely contained within the external ring. In addition, you cannot create an internal ring within an existing internal ring. Figure B-2 shows a polygon with one external ring with two internal rings.

Simple polygon with edges and vertices
Figure B-1. Simple polygon with edges and vertices
Complex polygon with inner and outer rings
Figure B-2. Complex polygon with inner and outer rings

Polygon Relationships

In MapPoint Web Service, like point data sources, a polygon data source requires a unique identity (known as “Entity ID value”). However, unlike point data sources, it is not mandatory to provide the values for the latitude and longitude coordinates; when the latitude and longitude coordinates are not assigned, the values will be automatically set to the latitude and longitude of the center point of the bounding rectangle for the polygon. Any valid polygon that is defined in the MapPoint Web Service data sources can be used for a variety of spatial relationship checks, depending on the business’s needs. For example, you can determine whether a latitude and longitude coordinate lies within a polygon. You can also determine whether a polygon is contained within another polygon (currently limited to a rectangle), or whether the rectangle and polygon are connected in any way. Figure B-3 shows the possible relationships between a rectangle and polygon.

Polygon spatial relationships
Figure B-3. Polygon spatial relationships

With this introduction, now let’s look at how you can prepare polygon data.

Rules for Preparing Polygon Data

You can manually create an XML file that contains the polygon data; however, the resulting XML file must contain the following requirements:

  • An embedded XSD schema with two namespaces :

  • A dataroot element, that contains:

    • One or more CustomerPolygonEntity elements

    • A generated attribute, which is set to a date-time value (for example, generated="2004-05-21T17:11:40")

The CustomerPolygonEntity element must contain the following elements:

EntityID

Unique ID within the given data source.

Latitude

If you do not provide this value, MapPoint Web Service calculates the latitude value and adds it during the upload process.

Longitude

If you do not provide this value, MapPoint Web Service calculates the Longitude value and adds it during the upload process.

EntityGeometry

References poly namespace http://s.mappoint.net/polygon-40/ .

The EntityGeometry element must contain a Polygon element. The Polygon element contains:

  • One ExteriorRing element

  • Zero or more InteriorRing elements

  • The value for an ExteriorRing or InteriorRing element is a list of latitude and longitude coordinate pairs separated by semicolons with no semicolon at the end of the list and with no spaces between any characters—for example, latitude1,longitude1;latitude2,longitude2

The following rules apply to the polygons in the ExteriorRing or InteriorRing element:

  • Each vertex is defined by a pair of latitude and longitude coordinate values.

  • No two latitude and longitude pairs can be the same within a polygon.

  • You do not need to close the polygon by specifying the final vertex of a polygon, as this will be a duplicate of the first vertex.

  • Internal polygons cannot overlap or intersect external polygons.

  • Each ring you define must contain at least three vertices.

Polygon Data Schema Document

The schema for the Polygon XML data document is as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:od="urn:schemas 
-microsoft-
    com:officedata">
     <xsd:schema>
      <xsd:element name="dataroot">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element ref="CustomerPolygonEntity" minOccurs="0" maxOccurs="unbounded"/
      >
          </xsd:sequence>
          <xsd:attribute name="generated" type="xsd:dateTime"/>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="CustomerPolygonEntity">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="EntityID" minOccurs="0" od:jetType="integer"
    od:sqlSType="smallint" type="xsd:short"/>
            <xsd:element name="Latitude" minOccurs="0" od:jetType="double"
    od:sqlSType="float" type="xsd:double"/>
            <xsd:element name="Longitude" minOccurs="0" od:jetType="double"
    od:sqlSType="float" type="xsd:double"/>
            <xsd:any namespace="##other" />
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
     </xsd:schema>

Polygon Data Sample Document

The following XML document shows a sample polygon that is defined with one exterior ring and one interior ring:

     <dataroot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" generated="2004-05-
    21T17:11:40">
      <CustomerPolygonEntity>
        <EntityID>1</EntityID>
        <Latitude>42.00</Latitude>
        <Longitude>-100.00</Longitude>
        <poly:EntityGeometry xmlns:poly="http://s.mappoint.net/polygon-40/">
          <Polygon>
            <ExteriorRing>40,-98;40,-102;44,-102;44,-98</ExteriorRing>
            <InteriorRing>41,-101;43,-100;41,-101</InteriorRing>
          </Polygon>
        </poly:EntityGeometry>
      </CustomerPolygonEntity>
     </dataroot>
    </root>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.123.147