Пример #1
0
def get_cells_in_feature(fea, resolution, return_cell_obj=False):
    geom = geojson_to_shape(fea['geometry'])
    cells = []
    if isinstance(geom, Point) or isinstance(geom, MultiPoint):
        # return cell object for Point or multiPoint
        curr_coords = list(coords(fea))
        for coord in curr_coords:
            cells.append(latlong_to_DGGS(coord, resolution))
    elif isinstance(geom, LineString) or isinstance(geom, MultiLineString):
        # return cell object for line
        fea['geometry']['coordinates'] = densify_my_line(
            fea['geometry']['coordinates'], resolution)
        curr_coords = list(coords(fea))
        cells = line_to_DGGS(curr_coords, resolution)
    elif isinstance(geom, Polygon):
        curr_coords = list(coords(fea))
        thisbbox = bbox(curr_coords)
        res_cells = cells_in_poly(thisbbox, [fea['geometry']['coordinates']],
                                  resolution, return_cell_obj)
        cells = [item[0] for item in res_cells]
    elif isinstance(geom, MultiPolygon):
        # return cell string
        curr_coords = list(coords(fea))
        thisbbox = bbox(curr_coords)
        res_cells = cells_in_poly(thisbbox, fea['geometry']['coordinates'],
                                  resolution, return_cell_obj)
        cells = [item[0] for item in res_cells]

    return cells
Пример #2
0
 def test_featurecollection(self):
     p1 = geojson.Feature(geometry=geojson.Point((-115.11, 37.11)))
     p2 = geojson.Feature(geometry=geojson.Point((-115.22, 37.22)))
     itr = coords(geojson.FeatureCollection([p1, p2]))
     pairs = list(itr)
     self.assertEqual(pairs[0], (-115.11, 37.11))
     self.assertEqual(pairs[1], (-115.22, 37.22))
Пример #3
0
def get_cells_in_feature(fea, resolution, return_cell_obj=False):
    geom = shape((fea['geometry']))
    cells = []
    if isinstance(geom, MultiLineString):
        # return cell object for line
        fea['geometry']['coordinates'] = densify_my_line(
            fea['geometry']['coordinates'], resolution)
        curr_coords = list(coords(fea))
        cells = line_to_DGGS(curr_coords, resolution)
    elif isinstance(geom, LineString):
        fea['geometry']['coordinates'] = densify_my_line(
            [fea['geometry']['coordinates']], resolution)
        curr_coords = list(coords(fea))
        cells = line_to_DGGS(curr_coords, resolution)

    return cells
Пример #4
0
def get_cells_in_feature(fea, resolution, cell_obj=True):
    #print("Type fea: {}".format(type(fea)))
    geom = geojson_to_shape(fea['geometry'])
    #print("Type geom: {}".format(type(geom)))
    curr_coords = list(coords(fea))
    thisbbox = bbox(curr_coords)
    #cells = poly_to_DGGS_tool(polygon, '', 10, input_bbox=thisbbox)  # start at DGGS level 10
    #listPolyCoords = list(polygon.exterior.coords)
    cells = []
    if isinstance(geom, LineString) or isinstance(geom, MultiLineString):
        #res_cells = line_to_DGGS(geom, resolution)  # start at DGGS level 10
        res_cells = line_to_DGGS(curr_coords,
                                 resolution)  # start at DGGS level 10
        cells = res_cells
    elif isinstance(geom, Polygon) or isinstance(geom, MultiPolygon):
        res_cells = cells_in_poly(
            thisbbox, curr_coords, resolution,
            return_cell_obj=True)  # start at DGGS level 10
        print(res_cells)
        cells = [item[0] for item in res_cells]
    else:  #try something anyway
        cells = cells_in_poly(thisbbox,
                              curr_coords,
                              resolution,
                              return_cell_obj=True)  # start at DGGS level 10
        print(res_cells)
        cells = [item[0] for item in res_cells]

    return cells
Пример #5
0
 def test_multipolygon(self):
     g = geojson.MultiPolygon([
         ([(3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28)],),
         ([(23.18, -34.29), (-1.31, -4.61),
           (3.41, 77.91), (23.18, -34.29)],)])
     itr = coords(g)
     pairs = list(itr)
     self.assertEqual(pairs[0], (3.78, 9.28))
     self.assertEqual(pairs[-1], (23.18, -34.29))
Пример #6
0
 def test_multipolygon(self):
     g = geojson.MultiPolygon([
         ([(3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28)],),
         ([(23.18, -34.29), (-1.31, -4.61),
           (3.41, 77.91), (23.18, -34.29)],)])
     itr = coords(g)
     pairs = list(itr)
     self.assertEqual(pairs[0], (3.78, 9.28))
     self.assertEqual(pairs[-1], (23.18, -34.29))
Пример #7
0
def geojson_centroid(obj):
    """
    Compute the centroid of the set of points that define the shapes in the
    input GeoJSON object.

    :param obj: a GeoJSON object.
    :return: the centroid if it could be calculated or ``None`` if there was
    an error---e.g. the input GeoJSON contains invalid points.
    """
    points = coords(obj)
    return best_effort_centroid2d(points)
Пример #8
0
 def test_geometrycollection(self):
     p1 = geojson.Point((-115.11, 37.11))
     p2 = geojson.Point((-115.22, 37.22))
     ln = geojson.LineString(
         [(-115.3, 37.3), (-115.4, 37.4), (-115.5, 37.5)])
     g = geojson.MultiPolygon([
         ([(3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28)],),
         ([(23.18, -34.29), (-1.31, -4.61),
           (3.41, 77.91), (23.18, -34.29)],)])
     itr = coords(geojson.GeometryCollection([p1, p2, ln, g]))
     pairs = set(itr)
     self.assertEqual(pairs, set([
         (-115.11, 37.11), (-115.22, 37.22),
         (-115.3, 37.3), (-115.4, 37.4), (-115.5, 37.5),
         (3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28),
         (23.18, -34.29), (-1.31, -4.61), (3.41, 77.91), (23.18, -34.29)
     ]))
Пример #9
0
 def test_point(self):
     itr = coords(geojson.Point((-115.81, 37.24)))
     self.assertEqual(next(itr), (-115.81, 37.24))
Пример #10
0
 def test_point_feature(self):
     itr = coords(geojson.Feature(geometry=geojson.Point((-115.81, 37.24))))
     self.assertEqual(next(itr), (-115.81, 37.24))
Пример #11
0
 def test_dict(self):
     itr = coords({'type': 'Point', 'coordinates': [-115.81, 37.24]})
     self.assertEqual(next(itr), (-115.81, 37.24))
Пример #12
0
 def test_point_rounding(self):
     itr = coords(geojson.Point(TOO_PRECISE))
     self.assertEqual(next(itr), tuple([round(c, 6) for c in TOO_PRECISE]))
Пример #13
0
 def test_point(self):
     itr = coords(geojson.Point((-115.81, 37.24)))
     self.assertEqual(next(itr), (-115.81, 37.24))
Пример #14
0
 def test_point_feature(self):
     itr = coords(geojson.Feature(geometry=geojson.Point((-115.81, 37.24))))
     self.assertEqual(next(itr), (-115.81, 37.24))
Пример #15
0
 def test_dict(self):
     itr = coords({'type': 'Point', 'coordinates': [-115.81, 37.24]})
     self.assertEqual(next(itr), (-115.81, 37.24))