I am trying to list all the columns (or features) and their types for a shapefile. shp2pgsql shows following schema:
CREATE TABLE "liberia" (gid serial,
"local_name" varchar(100),
"eng_name" varchar(100),
"cntry_name" varchar(75),
"type" varchar(75),
"cntry_code" varchar(10),
"continent" varchar(50),
"iso_code" varchar(10),
"volume" int4,
"id_7_1" varchar(100),
"id" numeric(10,0));
ALTER TABLE "liberia" ADD PRIMARY KEY (gid);
SELECT AddGeometryColumn('','liberia','geom','5578','MULTIPOLYGON',2);
The following code snippet tries to achieve that:
from osgeo import ogr
reader = ogr.Open("file.shp")
x = reader.GetLayer(0)
fields = x.schema
for l in ll:
print l.GetName()
print l.GetType()
Which prints output as follows:
LOCAL_NAME
4
ENG_NAME
4
CNTRY_NAME
4
...
I am facing two problems. One the geom column/feature is missing from the list and second deciphering type id to python or postgres type.