Friday, 1 December 2017

qgis - How to extract the US from a North America Shapefile?


I have a north america shapefile, downloaded from ftp://ftp.epa.gov/wed/ecoregions/cec_na/NA_CEC_Eco_Level2.zip


How can I get a new shapefile from this showing only us? Is there a way doing this in QGIS?


Thanks



Answer




You might find there are problems when trying to clip the NA_CEC_Eco shapefile layer with a US borders shapefile. The mask layer solution suggested above might be a better bet.


A slightly less clean way of working might be to load the NA_CEC_Eco shapefile into QGIS, style it and then export an image. So, load the shapefile and style it. Then arrange it on your screen so that it shows the Lower 48 with as little of Canada and Mexico as possible. Then export a georeferenced image of the screen view as a GeoTIFF (File -> Save as Image...).


Next, reproject your US borders shapefile to EPSG:2163. Load the shapefile into QGIS, right-click on it in the layers panel and go 'Save as..'. Select EPSG:2163 as the CRS for the new shapefile.


Now start a new QGIS project, load the georeferenced image and the reprojected borders shapefile, and clip the image with the shapefile (Raster -> Extraction -> Clipper). Tick the 'Mask layer' radio button and make sure that the borders shapefile is set as the mask layer. Also tick the 'Create an output alpha band' box.


Load the clipped image into a new QGIS project. It will have some alarming back borders, remove these by right-clicking on the layer in the layers panels and selecting 'Properties'. Select the 'Transparency' tab and set the 'Transparency band' to Band 5.


Overlay the clipped image with the borders shapefile, just to put a hard edge on the borders (obviously, remove the fill from the borders layer polygons).


A couple of points. Firstly, georeferenced screen images exported from QGIS are at the resolution of the screen, which is low (96 dpi, in my case). If you need a higher-resolution image you will have to export an image from the print composer and georeference it yourself. Secondly, to my way of thinking the NA_CEC_Eco shapefile is unnecessarily large and could do with simplifying. You could do this by going Vector -> Geometry Tools -> Simplify geometries and using 10 or 15 as the 'Simplify tolerance' value.


enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...