2

I have a shapefile with the roads from Europe and I want to export in a new shapefile only the roads from Greece. I tried to delete the other roads but there are too many and I have no attribute to help as an example country.

the attribute is

  gid serial NOT NULL,
  sourceid character varying(50),
  exs numeric,
  notes character varying(254),
  roadid character varying(50),
  onme character varying(200),
  rtenme character varying(200),
  ntlclass character varying(200),
  fclass numeric,
  crgway numeric,
  numlanes numeric,
  lnewidthm numeric,
  rdwidthm numeric,
  axleloadmt numeric,
  totloadmt numeric,
  srftpe numeric,
  srfcond numeric,
  srfprep numeric,
  isseasonal numeric,
  curntprac numeric,
  gdwthrprac numeric,
  bdwthrprac numeric,
  speedlimit numeric,
  curntspeed numeric,
  gnralspeed numeric,
  isundrcstr numeric,
  cstwrketc date,
  graddeg numeric,
  sec numeric,
  hasshouldr numeric,
  hassidewlk numeric,
  drivside numeric,
  iselevated numeric,
  hasmedian numeric,
  opstatus numeric,
  length_km numeric,
  shape_leng numeric,
  geom geometry(MultiLineString,4326),

I use postgres and now start to use QGIS

  • for details about the tools, please specify your software details. Otherwise only generic answers can be provided. – radouxju Oct 3 '14 at 6:36
  • It helps a lot if you specify what software you are using .. – Mark Cupitt Oct 3 '14 at 6:43
6

If you don't have an attribute, you should first find a polygon feature class with the boundaries of Greece (e.g. on gadm.org).

Then you have two solutions :

You want the roads to be cut at the boundaries of you area of interest : use some clip tools (in QGIS : Vector -> Geoprocessing -> Clip )

You want to keep the two sides of a road when it crosses a boundary. Use a selection by attribute, then export the results. (in QGIS : Vector->Research tools->Select by Location, then Save As...)

A compromise is to create a buffer (Vector -> Geoprocessing -> Buffer) around Greece and clip with the buffer, so that you keep the network connectivities but you don't have irregular pieces of roads outside the country.

3

You can also use a polygon to select the roads you want (in the top menu bar, the icon with the white arrow and the dotted lines). Then click on the layer containing the roads >> save as shapefile. If you make sure the box 'only save selected feautures' is thicked, you're new shapefile should only contain the selected roads.

1

If you have your data in PostGres/PostGIS, you can use the PostGIS pgsql2shp Dumper

4.4.2. Using the Dumper

The pgsql2shp table dumper connects directly to the database and converts a table (possibly defined by a query) into a shape file. The basic syntax is:

pgsql2shp [<options>] <database> [<schema>.]<table>

pgsql2shp [<options>] <database> <query>

Simply use CreateTableAs on your Europe Table to create a new table using a Bounding Box for Greece and ST_MakeEnvelop, something like this (untested):

CREATE TABLE greece_roads AS
SELECT *
FROM mytable
WHERE mytable.geom && ST_MakeEnvelope(left, bottom, right, top, 4326);

(left = Longitude, bottom=Latitude, right=Longitude, top= Latitude, 4326=Srid:WGS84)

Make sure the srid in your geom column matches the srid given in the ST_MakeEnvelope

&& is the Bounding Box Operator

Then use the table dumper to dump the new table to a shape file.

  • But Greece is not a box. Wouldn't it be better to take country borders as a polygon and select roads with ST_Intersects? – user30184 Oct 3 '14 at 21:15
  • I would imagine that the polygon would have a lot of points? Have never done it and no idea of the performance .. Possibly ST_MakeEnvelope then use ST_Intersects?? – Mark Cupitt Oct 4 '14 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.