如何在python2中使用geopandas移动多面

时间:2016-09-15 16:57:44

标签: python python-2.7 shapely geopandas

我是python中的GIS世界的新手(地缘,形状等)。我需要向上“移动”一个Multipolygon,但我不知道该怎么做。

问题

import pandas as pd
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
import seaborn as sns
import pysal as ps
from pysal.contrib.viz import mapping as maps    
import geopandas as gpd

fs = 5
nums = ("renta", 1)

f, ax = plt.subplots(1, figsize=(fs,fs))

spain.plot(column="XBAR", ax=ax, linewidth=0.05, cmap="OrRd", scheme="unique_values")
ax.set_axis_off()

plt.title("RENTA MEDIA", fontsize=20)
plt.tight_layout()

plt.savefig("../imgs/map_%s_%s.svg" % nums, bbox_iches="tight", dpi=2800)
plt.show()

输出:

正如你所看到的,群岛“Canarias”远离西班牙其他地区,我想要一个较小的数字,并且考虑到颜色很重要,它代表每个县的收入均值。

如果有帮助:

canarias = spain[spain.ca == "CANARIAS"]["geometry"]
print canarias
print canarias.type

13    (POLYGON ((-17.92791748046875 27.8495826721191...
Name: geometry, dtype: object
13    MultiPolygon
dtype: object

注意:县缺少,这就是为什么我没有这个县的数据。

我的第一次尝试是尝试更改多边形的坐标,例如,我试图找到如何做这样的一些:canarias.coords +( - 3,-4)但我没有找到如何访问coords多边形做到这一点。

我感谢任何帮助。

PS:对不起我的英文: - /

1 个答案:

答案 0 :(得分:4)

我认为您正在寻找shapely.affinity.translate。来自文档:

Signature: shapely.affinity.translate(geom, xoff=0.0, yoff=0.0, zoff=0.0)
Docstring:
Returns a translated geometry shifted by offsets along each dimension.

The general 3D affine transformation matrix for translation is:

/ 1  0  0 xoff \ 
| 0  1  0 yoff |
| 0  0  1 zoff |
\ 0  0  0   1  /

对于您的具体示例,您可以使用:

canarias = spain[spain.ca == "CANARIAS"].geometry
canarias_shift = canarias.apply(lambda x: shapely.affinity.translate(x, xoff=-3, yoff=-4))