コード例 #1
0
    def test_togeojson_with_multi_polygon(self):
        loop1 = [[-95.0, 40.0], [-95.5, 40.5], [-95.5, 40.0], [-95.0, 40.0]]
        loop2 = [[-95.2, 40.2], [-95.3, 40.2], [-95.3, 40.3], [-95.2, 40.2]]
        mpoly = sgeo.MultiPolygon([sgeo.Polygon(loop1), sgeo.Polygon(loop2)])

        json_poly = json.loads(utils.ToGeoJson(mpoly))
        self.assertIn('type', json_poly)
        self.assertEqual(json_poly['type'], 'MultiPolygon')
        self.assertIn('coordinates', json_poly)
        self.assertTrue(
            json_poly['coordinates'] == [[loop1], [list(reversed(loop2))]])
コード例 #2
0
    def test_togeojson_with_correct_winding(self):
        loop = [[-95.0, 40.0], [-95.5, 40.5], [-95.5, 40.0], [-95.0, 40.0]]
        hole = [[-95.2, 40.2], [-95.3, 40.3], [-95.3, 40.2], [-95.2, 40.2]]
        poly = sgeo.Polygon(loop, [hole])

        json_poly = json.loads(utils.ToGeoJson(poly))
        self.assertIn('type', json_poly)
        self.assertEqual(json_poly['type'], 'Polygon')
        self.assertIn('coordinates', json_poly)
        self.assertTrue(
            json_poly['coordinates'] == [loop, list(reversed(hole))])
コード例 #3
0
    def test_toshapely(self):
        poly = sgeo.Point(0, 0).buffer(1)
        poly_json = utils.ToGeoJson(poly)

        # Test for a generic geometry object.
        poly2 = utils.ToShapely(poly)
        self.assertEqual(poly2.difference(poly).area, 0)
        self.assertEqual(poly.difference(poly2).area, 0)

        # Test for a string geojson.
        poly2 = utils.ToShapely(poly_json)
        self.assertEqual(poly2.difference(poly).area, 0)
        self.assertEqual(poly.difference(poly2).area, 0)
コード例 #4
0
def PpaCreationModel(devices, pal_records):
    """Creates a PPA Polygon based on the PAL Records and Device Information
  Args:
    devices: A list of CBSD records (schema |CbsdRecordData|).
    pal_records: A list of pal records.
  Returns:
    The PPA polygon in GeoJSON format (string).
  """
    # Validation for Inputs
    for device in devices:
        logging.info('Validating device', device)
        util.assertContainsRequiredFields("RegistrationRequest.schema.json",
                                          device)
    for pal_rec in pal_records:
        logging.info('Validating pal_rec', pal_rec)
        util.assertContainsRequiredFields("PalRecord.schema.json", pal_rec)

    # Create Contour for each CBSD
    pool = mpool.Pool()
    device_polygon = pool.map(_GetPolygon, devices)

    # Create Union of all the CBSD Contours and Check for hole
    # after Census Tract Clipping
    contour_union = ops.cascaded_union(device_polygon)
    logging.info('contour_union = %s', contour_union)

    ppa_without_small_holes = utils.PolyWithoutSmallHoles(contour_union)
    logging.info('ppa_without_small_holes = %s', ppa_without_small_holes)

    ppa_polygon = _ClipPpaByCensusTract(ppa_without_small_holes, pal_records)
    logging.info('contour_union clipped by census tracts: %s', ppa_polygon)
    if ppa_polygon.is_empty:
        raise Exception("Empty Polygon is generated, please check the inputs.")
    if ppa_polygon.geom_type == "MultiPolygon":
        raise Exception(
            "Multi Polygon is not supported, please check the inputs.")

    # Convert Shapely Object to GeoJSON geometry string
    return utils.ToGeoJson(ppa_polygon)