def _get_self_bounds(self):
        """
        Computes the bounds of the object itself (not including it's children)
        in the form [[lat_min, lon_min], [lat_max, lon_max]].

        """
        if not self.embed:
            raise ValueError('Cannot compute bounds of non-embedded GeoJSON.')

        data = json.loads(self.data)
        if 'features' not in data.keys():
            # Catch case when GeoJSON is just a single Feature or a geometry.
            if not (isinstance(data, dict) and 'geometry' in data.keys()):
                # Catch case when GeoJSON is just a geometry.
                data = {'type': 'Feature', 'geometry': data}
            data = {'type': 'FeatureCollection', 'features': [data]}

        bounds = [[None, None], [None, None]]
        for feature in data['features']:
            for point in iter_points(
                    feature.get('geometry', {}).get('coordinates',
                                                    {})):  # noqa
                bounds = [
                    [
                        none_min(bounds[0][0], point[1]),
                        none_min(bounds[0][1], point[0]),
                    ],
                    [
                        none_max(bounds[1][0], point[1]),
                        none_max(bounds[1][1], point[0]),
                    ],
                ]
        return bounds
Пример #2
0
    def _get_self_bounds(self):
        """
        Computes the bounds of the object itself (not including it's children)
        in the form [[lat_min, lon_min], [lat_max, lon_max]].

        """
        if not self.embed:
            raise ValueError('Cannot compute bounds of non-embedded GeoJSON.')

        data = json.loads(self.data)
        if 'features' not in data.keys():
            # Catch case when GeoJSON is just a single Feature or a geometry.
            if not (isinstance(data, dict) and 'geometry' in data.keys()):
                # Catch case when GeoJSON is just a geometry.
                data = {'type': 'Feature', 'geometry': data}
            data = {'type': 'FeatureCollection', 'features': [data]}

        bounds = [[None, None], [None, None]]
        for feature in data['features']:
            for point in iter_points(feature.get('geometry', {}).get('coordinates', {})):  # noqa
                bounds = [
                    [
                        none_min(bounds[0][0], point[1]),
                        none_min(bounds[0][1], point[0]),
                        ],
                    [
                        none_max(bounds[1][0], point[1]),
                        none_max(bounds[1][1], point[0]),
                        ],
                    ]
        return bounds
Пример #3
0
    def _get_self_bounds(self):
        """
        Computes the bounds of the object itself (not including it's children)
        in the form [[lat_min, lon_min], [lat_max, lon_max]].

        """
        if not self.embed:
            raise ValueError("Cannot compute bounds of non-embedded GeoJSON.")

        data = json.loads(self.data)
        if "features" not in data.keys():
            # Catch case when GeoJSON is just a single Feature or a geometry.
            if not (isinstance(data, dict) and "geometry" in data.keys()):
                # Catch case when GeoJSON is just a geometry.
                data = {"type": "Feature", "geometry": data}
            data = {"type": "FeatureCollection", "features": [data]}

        bounds = [[None, None], [None, None]]
        for feature in data["features"]:
            for point in iter_points(feature.get("geometry", {}).get("coordinates", {})):  # noqa
                bounds = [
                    [none_min(bounds[0][0], point[1]), none_min(bounds[0][1], point[0])],
                    [none_max(bounds[1][0], point[1]), none_max(bounds[1][1], point[0])],
                ]
        return bounds
Пример #4
0
 def _get_self_bounds(self):
     """Computes the bounds of the object itself (not including it's children)
     in the form [[lat_min, lon_min], [lat_max, lon_max]]
     """
     bounds = [[None, None], [None, None]]
     for point in iter_points(self.data):
         bounds = [
             [
                 none_min(bounds[0][0], point[0]),
                 none_min(bounds[0][1], point[1]),
             ],
             [
                 none_max(bounds[1][0], point[0]),
                 none_max(bounds[1][1], point[1]),
             ],
         ]
     return bounds
Пример #5
0
 def _get_self_bounds(self):
     """Computes the bounds of the object itself (not including it's children)
     in the form [[lat_min, lon_min], [lat_max, lon_max]]
     """
     bounds = [[None, None], [None, None]]
     for point in iter_points(self.data):
         bounds = [
             [
                 none_min(bounds[0][0], point[0]),
                 none_min(bounds[0][1], point[1]),
             ],
             [
                 none_max(bounds[1][0], point[0]),
                 none_max(bounds[1][1], point[1]),
             ],
         ]
     return bounds