Мне нужна информация колонки FID от Shapefile. Каким -то образом этот столбец не «показан», когда вы загружаете ShapeFile. I need the information of that column because I need to say something like:
fid
id
label
< /thead>
1 < /td>
1 < /td>
forest < /td>
< /tr>
2 < /td>
1 1 1 1 1 1 1 1 1 1 1 1 1 1 /> Forest < /td>
< /tr>
3 < /td>
2 < /td>
вода < /td>
< /tr>
4 < /td>
< /tr>
4
< /tr /> вода < /td>
< /tr>
5 < /td>
3 < /td>
ourban < /td>
< /tr>
< /tbody>
< /table>
< /> Для IDS X, Y, Z и т. Д. Я попробовал следующее в Geopandas. Есть ли более эффективный способ сделать это с помощью геопанд или OGR от Osgeo? Спасибо < /p>
import os
import geopandas as gpd
import numpy as np
from osgeo import ogr
# open the training data
train_cl_fn = os.path.join(src, "train.shp")
# read the column "id" that already exists. This id column says that feature X belongs to id Y
X_train_G = gpd.read_file(train_cl_fn)
class_ids = X_train_G["id"].unique()
print('class ids: ', class_ids)
# I create an empty array for the fids
class_fids = np.array([])
print('class labels: ', class_fids)
# add "fidl" column, using "id" and the empty array
# FID and fid are the same, therefore "fidl"
X_train_G['fidl'] = X_train_G['id'].map(dict(zip(class_ids, class_fids)))
print(X_train_G.head())
# export: rewrite file
X_train_G.to_file(os.path.join(src, "train.shp"))
# open the SAME file again, this time in ogr
train_cl_fn = os.path.join(src, "train.shp")
driver = ogr.GetDriverByName('ESRI Shapefile')
train_ds = driver.Open(train_cl_fn, 1) # 0 means read-only. 1 means writeable.
layer = train_ds.GetLayer()
for Ft in layer:
ThisID = int(Ft.GetFID())
#print('id is {}'.format(ThisID))
Ft.SetField('fidl',ThisID) # Write the FID to the fidl field
layer.SetFeature(Ft) # update the feature
dataSource = None # save/rewrite file with fid info in the fidl column
Подробнее здесь: https://stackoverflow.com/questions/661 ... das-python
Создайте колонку FID в ShapeFile в OGR или Geopandas Python ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Geopandas: как читать CSV и конвертировать в фрейм данных GeoPandas с многоугольниками?
Anonymous » » в форуме Python - 0 Ответы
- 37 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Geopandas: Как прочитать CSV и преобразовать в Geopandas DataFrame с полигонами?
Anonymous » » в форуме Python - 0 Ответы
- 16 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Geotools OGR плагин - неудовлетворенная линкуратор (OGRJI или GDALALLJNI)
Anonymous » » в форуме JAVA - 0 Ответы
- 6 Просмотры
-
Последнее сообщение Anonymous
-