Changing long, lat values of Polygon coordinates in python

Robert O'Brien

I have a basic shape file of all the us states which can be found here..

shapefile

I am looking to edit the positions of the 2 states hawaii and alaska, i wish to change the coordinates of the state of hawaii so that it roughly sits under the state of nevada, and i also with to change the state of alaska so that is is considerably smaller.. and also so it sits roughly below both the state of california and Arizona, il include an image just so theres a visual of my idea.. enter image description here

as you can see alaska and hawaii are sitting on the bottom left of the large us mainland just under the states mentioned before.

I know for this to happen i need to change the longitude and latitude coordinates of both states using geopandas etc.

So i started off with the state of hawaii and began accessing the polygons coordinates using numpy. here is a snippet of the code so far

import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
from shapely.geometry import Point, Polygon
import numpy as np

poly_States = gpd.read_file("states.shp")
hawaii = poly_States[poly_States.STATE_ABBR == "HI"]
coords = [i for i in hawaii.geometry]

all_Coords = []
for b in coords[0].boundary:
    coords = np.dstack(b.coords.xy).tolist()
    all_Coords.append(*coords)

for cord_1 in all_Coords:
    for cord2 in cord_1:
        cord2[0] = cord2[0] + 54.00000000000000

my idea here was to access the coordinates in array format and change the latitude coordinates by adding 54, so basically shifting the entire state to the right to have it sitting rougly under new mexico.

my issue lies in actually returning theses changes to the polygon object in the shapefile itself. i feel like there is probably an easier method maybe by accessing attributes of the polygon or using some sort of external software, but i believe that if im able to properly access the long,lat values and change them i should be able to make the changes in positioning and size that i need.

Thanks in advance.

Stef

You can use translate and assign the new geometry like this:

m = poly_States.STATE_ABBR == "HI"
poly_States[m] = poly_States[m].set_geometry(poly_States[m].translate(54))

Result: shifted Hawaii

The same way you can scale and shift Alaska:

m = poly_States.STATE_ABBR == "AK"
poly_States[m] = poly_States[m].set_geometry(poly_States[m].scale(.2,.2,.2).translate(40, -40))

enter image description here

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

transform lat long coordinates for a osmnx projected map

Average lat long with coordinates in XSLT 1.0

PyProj transformation from CA state plane coordinates to Lat, Long not as expected

Incorrect NA return when converting Lat/Long Coordinates to location in R

Creating coordinates for polygon using Python lists

R: Changing values from raster at certain coordinates

Postgis query ST_DWithin against lat/long values

Get the coordinates of two polygon's intersection area (in Python)

How do I retrieve lat & long coordinates from the client without them needing to POST once?

Expected two (lat, lon) values for location, python

Como converter o UTM para Lat / Long em Python?

posição de pixel / array para lat long gdal Python

python xarray select by lat/long and extract point data to dataframe

Get lat and long

Changing the values in a column using python

Python: Changing values of a nested list

Comparing two lists of coordinates in python and using coordinate values to assign values

Referência espacial Lat / Long

Rotas falsas (lat long) lib

Atualizando Google Maps Long / Lat

Como exibir a lat long long no ios?

plot LAT/LON coordinates on geotiff in R

Unnest a nested list of lat/lon coordinates in R?

Measure distance between lat/lon coordinates and utm coordinates

Medindo a distância entre dois pontos lat long em 1000 em Python

Python plotando coordenadas separadas por vírgulas (lat, long) no mapa base matplotlib

Converter uma coluna de dados MULTIPOLYGON em lat e long em python

Extending python dictionary and changing key values

Qgis: How to export polygon shapefile with coordinates in degrees