你们都好吗..谢谢您的光临。 我已经通过matplotlib函数绘制了使用xgboost模态制作的预测图,并且希望将此图另存为shapefile,以便可以在ArcGIS中使用它,但是保存代码给我一个错误...
#test_df['probability'] = np.minimum(pred,0.300)
fig,ax = plt.subplots()
fig.set_size_inches((15,15))
test_df.plot(ax=ax,column='probability',cmap=cmap)
plt.gca().set_facecolor('k')
plt.imshow(np.array([[test_df.probability.min(),test_df.probability.max()]]),origin='lower',cmap=cmap)
test_collisions.plot.scatter(x='Longitude',y='Latitude',
ax=ax,
s=500,
color='w',
zorder=9e99,
marker='*',
edgecolors='r')
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
ax.set_xbound(lower=x0,upper=x1)
ax.set_ybound(lower=y0,upper=y1)
plt.colorbar(cax=cax)
from geopandas.io.file import to_file
test_df.to_file('MyGeometriesSRSH.shp', driver='ESRI Shapefile')
我又回来了
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-58-76c92c6ff400> in <module>()
1 from geopandas.io.file import to_file
----> 2 test_df.to_file('MyGeometriesSRSH.shp', driver='ESRI Shapefile')
~\Anaconda3\envs\arcpro\lib\site-packages\geopandas\geodataframe.py in to_file(self, filename, driver, schema, **kwargs)
411 """
412 from geopandas.io.file import to_file
--> 413 to_file(self, filename, driver, schema, **kwargs)
414
415 def to_crs(self, crs=None, epsg=None, inplace=False):
~\Anaconda3\envs\arcpro\lib\site-packages\geopandas\io\file.py in to_file(df, filename, driver, schema, **kwargs)
115 with fiona.open(filename, 'w', driver=driver, crs=df.crs,
116 schema=schema, **kwargs) as colxn:
--> 117 colxn.writerecords(df.iterfeatures())
118
119
~\Anaconda3\envs\arcpro\lib\site-packages\fiona\collection.py in writerecords(self, records)
347 if self.mode not in ('a', 'w'):
348 raise IOError("collection not open for writing")
--> 349 self.session.writerecs(records, self)
350 self._len = self.session.get_length()
351 self._bounds = self.session.get_extent()
fiona/ogrext.pyx in fiona.ogrext.WritingSession.writerecs()
fiona/ogrext.pyx in fiona.ogrext.OGRFeatureBuilder.build()
ValueError: Invalid field type <class 'pandas._libs.tslibs.timestamps.Timestamp'>
test_df
Index(['segment_id', 'OBJECTID_1', 'Join_Count', 'TARGET_FID', 'Join_Count_1',
'TARGET_FID_1', 'Join_Count_12', 'TARGET_FID_12', 'OBJECTID', 'pre_dir',
'street_type', 'suf_dir', 'one_way', 'speed_limit', 'surface_type',
'surface_width', 'aadt', 'sinuosity', 'euclidean_length',
'segment_length', 'at_intersection', 'near_billboard',
'road_orient_approx', 'proximity_to_signal', 'proximity_to_billboard',
'proximity_to_nearest_intersection', 'proximity_to_major_road',
'population_density', 'station_id', 'SHAPE', 'accident_counts',
'geometry', 'scaled', 'timestamp', 'hour', 'weekday', 'month',
'wind_speed', 'visibility', 'temperature', 'precip_depth', 'snow_depth',
'snowing', 'raining', 'foggy', 'icy', 'hailing', 'thunderstorm'],
dtype='object')
并且偏好的格式为
test_collisions = collisions[(prediction_time - datetime.timedelta(microseconds=0)).isoformat():(prediction_time + datetime.timedelta(microseconds=3600)).isoformat()]
任何人都可以引导我使用正确的代码来估计您的时间...