我试图找到距离1公里范围内的所有最近邻居.这是我构建树和搜索最近点的脚本,
from pysal.cg.kdtree import KDTree
def construct_tree(s):
data_geopoints = [tuple(x) for x in s[['longitude','latitude']].to_records(index=False)]
tree = KDTree(data_geopoints, distance_metric='Arc', radius=pysal.cg.RADIUS_EARTH_KM)
return tree
def get_neighbors(s,tree):
indices = tree.query_ball_point(s, 1)
return indices
#Constructing the tree for search
tree = construct_tree(data)
#Finding the nearest neighbours within 1KM
data['neighborhood'] = data['lat_long'].apply(lambda row: get_neighbors(row,tree))
Run Code Online (Sandbox Code Playgroud)
从我在pysal页面上看到的内容,它说 -
kd-tree建立在scipy的kd-tree功能之上.如果使用scipy 0.12或更高版本使用scipy.spatial.cKDTree,否则使用scipy.spatial.KDTree.
在我的情况下,它应该使用cKDTree.这适用于样本数据集,但由于tree.query_ball_point返回索引列表作为结果.每个列表将包含100个元素.对于我的数据点(200万条记录),这种情况越来越大,并且由于某些点后的内存问题而停止.关于如何解决这个问题的任何想法?
我正在寻找一种有效的方法来找到给定多边形的一阶邻域.我的数据是shapefile格式.
我的第一个想法是计算多边形质心的x和y坐标,以便找到邻居的质心.
import pysal
from pysal.common import *
import pysal.weights
import numpy as np
from scipy import sparse,float32
import scipy.spatial
import os, gc, operator
def get_points_array_from_shapefile(inFile):
"""
Gets a data array of x and y coordinates from a given shape file
Parameters
----------
shapefile: string name of a shape file including suffix
Returns
-------
points: array (n,2) a data array of x and y coordinates
Notes
-----
If the given shape file includes polygons,
this function returns x …Run Code Online (Sandbox Code Playgroud) 我正在使用pysal空间回归。这就是我正在做的事情。我首先划分训练集和验证集
import pysal as ps
m_train = ps.model.spreg.GM_Lag(ytrain, xtrain, w=w_train, spat_diag=True)
Run Code Online (Sandbox Code Playgroud)
如何使用 的系数m_train在验证集上测试模型?
print(m_train.summary)
REGRESSION
----------
SUMMARY OF OUTPUT: SPATIAL TWO STAGE LEAST SQUARES
--------------------------------------------------
Data set : unknown
Weights matrix : unknown
Dependent Variable : dep_var Number of Observations: 138
Mean dependent var : 0.2200 Number of Variables : 12
S.D. dependent var : 2.2411 Degrees of Freedom : 126
Pseudo R-squared : 0.6609
Spatial Pseudo R-squared: omitted due to rho outside the boundary (-1, …Run Code Online (Sandbox Code Playgroud) 我使用该statsmodels包来估计我的 OLS 回归。现在我想要Breusch Pagan test。我在pysal这个测试中使用了这个包,但这个函数返回一个错误:
import statsmodels.api as sm
import pysal
model = sm.OLS(Y,X,missing = 'drop')
rs = model.fit()
pysal.spreg.diagnostics.breusch_pagan(rs)
Run Code Online (Sandbox Code Playgroud)
返回错误:
AttributeError: 'OLSResults' 对象没有属性 'u'
我该怎么办?
我正在寻找一种方法来格式化/舍入由.plot()GeoPandas 中的函数生成的那些地图中的数字图例标签。例如:
gdf.plot(column='pop2010', scheme='QUANTILES', k=4)
Run Code Online (Sandbox Code Playgroud)
这给了我一个带有许多小数位的图例:
我希望图例标签是整数。
my_table我在 PostgreSQL 数据库中有一个点表,其中包含geometry列和其他属性。我有一些my_table如下的示例数据( 的属性my_table)。
id val1
1 72.54513286
2 73.67371014
3 74.204424
4 73.76017279
5 77.7912762
6 77.78789496
7 65.51822878
8 65.5182287
9 74.65885753
10 74.65885753
11 61.18084042
12 60.75827621
13 64.27716322
14 63.69432836
15 75.790405
16 60.95270235
17 79.12399503
18 62.9667706
19 78.1265630
Run Code Online (Sandbox Code Playgroud)
使用 Python PySAL包,我想分析列中的值是否val1空间自相关(Moran I)(通过交互绘制它们)。我的交互式空间自相关的预期输出可能如下(图像来源,此处):
我是Python新手。有人可以建议我如何使用 PySAL 执行此操作吗?
我想并排绘制两个 tematic 地图以进行比较。我正在使用 geopandas 绘制地图和 pysal 从空间分析生成地图。
pysal ×7
python ×7
geopandas ×2
canopy ×1
geometry ×1
maps ×1
matplotlib ×1
python-2.7 ×1
scipy ×1
shapefile ×1
spatial ×1
statistics ×1