Ejemplo n.º 1
0
Archivo: mesh.py Proyecto: pslh/nhlib
    def get_convex_hull(self):
        """
        Get a convex polygon object that contains projections of all the points
        of the mesh.

        :returns:
            Instance of :class:`nhlib.geo.polygon.Polygon` that is a convex
            hull around all the points in this mesh. If the original mesh
            had only one point, the resulting polygon has a square shape
            with a side length of 10 meters. If there were only two points,
            resulting polygon is a stripe 10 meters wide.
        """
        # avoid circular imports
        from nhlib.geo.polygon import Polygon
        # create a projection centered in the center of points collection
        proj = geo_utils.get_orthographic_projection(
            *geo_utils.get_spherical_bounding_box(self.lons, self.lats)
        )
        # project all the points and create a shapely multipoint object.
        # need to copy an array because otherwise shapely misinterprets it
        coords = numpy.transpose(proj(self.lons, self.lats)).copy()
        multipoint = shapely.geometry.MultiPoint(coords)
        # create a 2d polygon from a convex hull around that multipoint
        polygon2d = multipoint.convex_hull
        # if mesh had only one point, the convex hull is a point. if there
        # were two, it is a line string. we need to return a convex polygon
        # object, so extend that area-less geometries by some arbitrarily
        # small distance, like five meters.
        if isinstance(polygon2d, (shapely.geometry.LineString,
                                  shapely.geometry.Point)):
            polygon2d = polygon2d.buffer(0.005, 1)
        return Polygon._from_2d(polygon2d, proj)
Ejemplo n.º 2
0
Archivo: point.py Proyecto: angri/nhlib
    def to_polygon(self, radius):
        """
        Create a circular polygon with specified radius centered in the point.

        :param radius:
            Required radius of a new polygon, in km.
        :returns:
            Instance of :class:`~nhlib.geo.polygon.Polygon` that approximates
            a circle around the point with specified radius.
        """
        assert radius > 0
        # avoid circular imports
        from nhlib.geo.polygon import Polygon
        # get a projection that is centered in the point
        proj = geo_utils.get_orthographic_projection(
            self.longitude, self.longitude, self.latitude, self.latitude
        )
        # create a shapely object from a projected point coordinates,
        # which are supposedly (0, 0)
        point = shapely.geometry.Point(*proj(self.longitude, self.latitude))
        # extend the point to a shapely polygon using buffer()
        # and create nhlib.geo.polygon.Polygon object from it
        return Polygon._from_2d(point.buffer(radius), proj)
Ejemplo n.º 3
0
    def to_polygon(self, radius):
        """
        Create a circular polygon with specified radius centered in the point.

        :param radius:
            Required radius of a new polygon, in km.
        :returns:
            Instance of :class:`~nhlib.geo.polygon.Polygon` that approximates
            a circle around the point with specified radius.
        """
        assert radius > 0
        # avoid circular imports
        from nhlib.geo.polygon import Polygon
        # get a projection that is centered in the point
        proj = geo_utils.get_orthographic_projection(self.longitude,
                                                     self.longitude,
                                                     self.latitude,
                                                     self.latitude)
        # create a shapely object from a projected point coordinates,
        # which are supposedly (0, 0)
        point = shapely.geometry.Point(*proj(self.longitude, self.latitude))
        # extend the point to a shapely polygon using buffer()
        # and create nhlib.geo.polygon.Polygon object from it
        return Polygon._from_2d(point.buffer(radius), proj)
Ejemplo n.º 4
0
Archivo: mesh.py Proyecto: angri/nhlib
    def get_convex_hull(self):
        """
        Get a convex polygon object that contains projections of all the points
        of the mesh.

        :returns:
            Instance of :class:`nhlib.geo.polygon.Polygon` that is a convex
            hull around all the points in this mesh. If the original mesh
            had only one point, the resulting polygon has a square shape
            with a side length of 10 meters. If there were only two points,
            resulting polygon is a stripe 10 meters wide.
        """
        proj, polygon2d = self._get_proj_convex_hull()
        # if mesh had only one point, the convex hull is a point. if there
        # were two, it is a line string. we need to return a convex polygon
        # object, so extend that area-less geometries by some arbitrarily
        # small distance.
        if isinstance(polygon2d, (shapely.geometry.LineString,
                                  shapely.geometry.Point)):
            polygon2d = polygon2d.buffer(self.DIST_TOLERANCE, 1)

        # avoid circular imports
        from nhlib.geo.polygon import Polygon
        return Polygon._from_2d(polygon2d, proj)
Ejemplo n.º 5
0
Archivo: mesh.py Proyecto: angri/nhlib
    def get_convex_hull(self):
        """
        Get a convex polygon object that contains projections of all the points
        of the mesh.

        :returns:
            Instance of :class:`nhlib.geo.polygon.Polygon` that is a convex
            hull around all the points in this mesh. If the original mesh
            had only one point, the resulting polygon has a square shape
            with a side length of 10 meters. If there were only two points,
            resulting polygon is a stripe 10 meters wide.
        """
        proj, polygon2d = self._get_proj_convex_hull()
        # if mesh had only one point, the convex hull is a point. if there
        # were two, it is a line string. we need to return a convex polygon
        # object, so extend that area-less geometries by some arbitrarily
        # small distance.
        if isinstance(polygon2d,
                      (shapely.geometry.LineString, shapely.geometry.Point)):
            polygon2d = polygon2d.buffer(self.DIST_TOLERANCE, 1)

        # avoid circular imports
        from nhlib.geo.polygon import Polygon
        return Polygon._from_2d(polygon2d, proj)