def define_origin(geojson, origin): if not origin: origin = "centroid" if isinstance(origin, list): return get_coord(origin) bb = bbox(geojson) west = bb[0] south = bb[1] east = bb[2] north = bb[3] if (origin == "sw" or origin == "southwest" or origin == "westsouth" or origin == "bottomleft"): return [west, south] elif (origin == "se" or origin == "southeast" or origin == "eastsouth" or origin == "bottomright"): return [east, south] elif (origin == "nw" or origin == "northwest" or origin == "westnorth" or origin == "topleft"): return [west, north] elif (origin == "ne" or origin == "northeast" or origin == "eastnorth" or origin == "topright"): return [east, north] elif origin == "center": return center(geojson)["geometry"]["coordinates"] elif origin is None or origin == "centroid": return centroid(geojson)["geometry"]["coordinates"] else: raise Exception("invalid origin")
def transform_rotate( feature: Union[List[Feature], FeatureCollection], angle: float, pivot: list = None, mutate: bool = False, ): """ Rotates any geojson Feature or Geometry of a specified angle, around its centroid or a given pivot point; all rotations follow the right-hand rule. :param feature: Geojson to be rotated. :param angle: angle of rotation (along the vertical axis), from North in decimal degrees, negative clockwise :param pivot: point around which the rotation will be performed :param mutate: allows GeoJSON input to be mutated (significant performance increase if True) :return: the rotated GeoJSON Example :- >>> from turfpy.transformation import transform_rotate >>> from geojson import Polygon, Feature >>> f = Feature(geometry=Polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]])) >>> pivot = [0, 25] >>> transform_rotate(f, 10, pivot) """ if not feature: raise Exception("geojson is required") if angle == 0: return feature if not pivot: pivot = centroid(feature)["geometry"]["coordinates"] if not mutate: feature = copy.deepcopy(feature) def _callback_coord_each( coord, coord_index, feature_index, multi_feature_index, geometry_index ): nonlocal pivot, angle initial_angle = rhumb_bearing(GeoPoint(pivot), GeoPoint(coord)) final_angle = initial_angle + angle distance = rhumb_distance(GeoPoint(pivot), GeoPoint(coord)) new_coords = get_coord(rhumb_destination(GeoPoint(pivot), distance, final_angle)) coord[0] = new_coords[0] coord[1] = new_coords[1] coord_each(feature, _callback_coord_each) return feature
# # Close table # print('</tbody></table>') # print('<!-- /wp:table -->') elif (action == 'pins'): # pinsCache = '/tmp/places/' + country + \ # '_pins_' + str(checksum) + '.geojson' # if not Path(pinsCache).is_file(): if True: pins = { "type": "FeatureCollection", "generator": "JOSM", "features": [] } for feature in myPlaces['features']: # print(feature) centroid_ = centroid(feature) centroid_['properties'] = feature['properties'] centroid_['properties']['title'] = feature['properties']['place'] pins['features'].append(centroid_) # with open(pinsCache, 'w') as outfile: # json.dump(pins, outfile) format = arg3 if (format == 'html'): print('Content-type: text/html') print('') lastCountry = '' print('<!DOCTYPE html><html><body><table border=4><tr>') print('<td>map</td>') print('<td>gmaps</td>') print('<td>osm</td>')