Example #1
0
 def __init__(self, layer, filename, zoom, x, y):
     MapGeoJSONTile.__init__(self, layer, filename, zoom, x, y)
     self.labels = []
     if zoom >= 16:  # labels appear
         for id, polygon, properties, style in self.polygons:
             geojson = json.loads(properties['centroid'])
             coordinates = geojson['coordinates']
             center = project_to_tilespace_pixel(coordinates[1],
                                                 coordinates[0], zoom, x, y)
             # If the label center is within this tile, use it.
             if center[0] >= 0 and center[0] < 256 and center[
                     1] > 0 and center[1] < 256:
                 house_number = properties.get("house_number")
                 street = properties.get("street")
                 if house_number and street:  # not None and not blank
                     self.labels.append((center, house_number, street))
Example #2
0
def _project_to_tilespace_pixels(coordinates, zoom, xtile, ytile):
    return map(
        lambda p: project_to_tilespace_pixel(p[1], p[0], zoom, xtile, ytile),
        coordinates)
Example #3
0
    def load_geojson(self, geojson):
        points = self.points
        lines = self.lines
        polygons = self.polygons

        assert geojson['type'] == 'FeatureCollection'
        features = geojson['features']
        if self.sort_key is not None:
            features = sorted(
                features,
                key=lambda feature: feature['properties'][self.sort_key])

        for feature in features:
            assert feature['type'] == 'Feature'
            id = feature.get('id', None)
            properties = feature['properties']
            geometry = feature['geometry']

            if geometry["type"] == 'GeometryCollection':
                geometries = geometry["geometries"]
            else:
                geometries = [geometry]

            for geometry in geometries:
                geometry_type = geometry['type']

                try:
                    coordinates = geometry['coordinates']
                except KeyError:
                    print("Warning: broken geometry:", feature)
                    continue

                if geometry_type == 'Point':
                    style = self.choose_point_style(properties)
                    if style is not None:
                        point = project_to_tilespace_pixel(
                            coordinates[1], coordinates[0], self.zoom, self.x,
                            self.y)
                        points.append((id, point, properties, style))
                    continue

                if geometry_type == 'LineString':
                    style = self.choose_line_style(properties)
                    if style is not None:
                        line = project_to_tilespace_pixels(
                            coordinates, self.zoom, self.x, self.y)
                        lines.append((id, line, properties, style))
                    continue

                if geometry_type == 'MultiLineString':
                    style = self.choose_line_style(properties)
                    if style is not None:
                        for coordinates2 in coordinates:
                            line = project_to_tilespace_pixels(
                                coordinates2, self.zoom, self.x, self.y)
                            lines.append((id, line, properties, style))
                    continue

                if geometry_type == 'Polygon':
                    style = self.choose_polygon_style(properties)
                    if style is not None:
                        for coordinates2 in coordinates:
                            polygon = project_to_tilespace_pixels(
                                coordinates2, self.zoom, self.x, self.y)
                            polygons.append((id, polygon, properties, style))
                    continue

                if geometry_type == 'MultiPolygon':
                    style = self.choose_polygon_style(properties)
                    if style is not None:
                        for coordinates2 in coordinates:
                            for coordinates3 in coordinates2:
                                polygon = project_to_tilespace_pixels(
                                    coordinates3, self.zoom, self.x, self.y)
                                polygons.append(
                                    (id, polygon, properties, style))
                    continue

                print("Warning: unimplemented geometry type:", feature)
def _project_to_tilespace_pixels(coordinates, zoom, xtile, ytile):
	return map(lambda p: project_to_tilespace_pixel(p[1], p[0], zoom, xtile, ytile), coordinates)
	def load_geojson(self, geojson):
		points = self.points
		lines = self.lines
		polygons = self.polygons

		assert geojson['type'] == 'FeatureCollection'
		features = geojson['features']
		if self.sort_key is not None:
			features = sorted(features, key=lambda feature: feature['properties'][self.sort_key])

		for feature in features:
			assert feature['type'] == 'Feature'
			id = feature.get('id', None)
			properties = feature['properties']
			geometry = feature['geometry']

			if geometry["type"] == 'GeometryCollection':
				geometries = geometry["geometries"]
			else:
				geometries = [geometry]

			for geometry in geometries:
				geometry_type = geometry['type']
	
				try:
					coordinates = geometry['coordinates']
				except KeyError:
					print("Warning: broken geometry:", feature)
					continue
	
				if geometry_type == 'Point':
					style = self.choose_point_style(properties)
					if style is not None:
						point = project_to_tilespace_pixel(coordinates[1], coordinates[0], self.zoom, self.x, self.y)
						points.append((id, point, properties, style))
					continue
	
				if geometry_type == 'LineString':
					style = self.choose_line_style(properties)
					if style is not None:
						line = project_to_tilespace_pixels(coordinates, self.zoom, self.x, self.y)
						lines.append((id, line, properties, style))
					continue
	
				if geometry_type == 'MultiLineString':
					style = self.choose_line_style(properties)
					if style is not None:
						for coordinates2 in coordinates:
							line = project_to_tilespace_pixels(coordinates2, self.zoom, self.x, self.y)
							lines.append((id, line, properties, style))
					continue
	
				if geometry_type == 'Polygon':
					style = self.choose_polygon_style(properties)
					if style is not None:
						for coordinates2 in coordinates:
							polygon = project_to_tilespace_pixels(coordinates2, self.zoom, self.x, self.y)
							polygons.append((id, polygon, properties, style))
					continue
	
				if geometry_type == 'MultiPolygon':
					style = self.choose_polygon_style(properties)
					if style is not None:
						for coordinates2 in coordinates:
							for coordinates3 in coordinates2:
								polygon = project_to_tilespace_pixels(coordinates3, self.zoom, self.x, self.y)
								polygons.append((id, polygon, properties, style))
					continue
	
				print("Warning: unimplemented geometry type:", feature)
def project_to_tilespace_pixels(coordinates, zoom, xtile, ytile):
    points = map(
        lambda p: project_to_tilespace_pixel(p[1], p[0], zoom, xtile, ytile),
        coordinates)
    return list(points)
def project_to_tilespace_pixels(coordinates, zoom, xtile, ytile):
	points = map(lambda p: project_to_tilespace_pixel(p[1], p[0], zoom, xtile, ytile), coordinates)
	return list(points)