Beispiel #1
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
Beispiel #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',{})):
                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
Beispiel #3
0
    def get_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 TopoJSON.')

        xmin, xmax, ymin, ymax = None, None, None, None

        for arc in self.data['arcs']:
            x, y = 0, 0
            for dx, dy in arc:
                x += dx
                y += dy
                xmin = none_min(x, xmin)
                xmax = none_max(x, xmax)
                ymin = none_min(y, ymin)
                ymax = none_max(y, ymax)
        return [
            [
                self.data['transform']['translate'][1] + self.data['transform']['scale'][1] * ymin,  # noqa
                self.data['transform']['translate'][0] + self.data['transform']['scale'][0] * xmin  # noqa
            ],
            [
                self.data['transform']['translate'][1] + self.data['transform']['scale'][1] * ymax,  # noqa
                self.data['transform']['translate'][0] + self.data['transform']['scale'][0] * xmax  # noqa
            ]
        ]
Beispiel #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 self.data:
         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
Beispiel #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 self.data:
         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