I have a MultiLineString postgis layer in a db. The layer is created with the following...
-- Table: public.pipe_clip_102737
-- DROP TABLE public.pipe_clip_102737;
CREATE TABLE public.pipe_clip_102737
(
geom geometry(MultiLineString,102737),
gid integer NOT NULL DEFAULT nextval('pipe_clip_102737_gid_seq'::regclass),
CONSTRAINT pipe_clip_102737_pkey PRIMARY KEY (gid)
)
WITH (
OIDS=FALSE
);
ALTER TABLE public.pipe_clip_102737
OWNER TO jcfcqrso;
-- Index: public.pipe_clip_102737_geom_idx
-- DROP INDEX public.pipe_clip_102737_geom_idx;
CREATE INDEX pipe_clip_102737_geom_idx
ON public.pipe_clip_102737
USING gist
(geom);
The layer displays correctly in both ArcGIS and QGIS when connecting directly to the db.
However will not display when I try to export to shp via cmd line or via the PostGIS DBF and Shapefile Loader utility.
pgsql2shp -f package/pipe_clip3.shp -h xxxxxxxxxxxxxxxxxxx -u xxxxx -P xxxxxxxx routing "SELECT gid, geom FROM pipe_clip_102737"
Both methods dump 1727 records as a shp. But cannot be displayed. ArcGIS displays:
"Error opening feature class. Number of shapes does not match number of records."
and QGIS seems to be aware of the extents of the shp but will not draw features and table is empty.
Why can I successfully display db table but not export a usable shp using either method?
EDIT: The issue seems to be related to the cloumn name gid. As mentioned by @tinlyx renaming the gid column while running the cmd seem to fix the problem.
pgsql2shp -f myshape.shp -h xx.xx.xx.xx -u myuser -P xxxxx mydb "SELECT gid as myid, geom FROM mytable;"