Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Invalid Coordinates Using shp2dta

    Hello,

    I am trying to match latitude and longitude coordinates from a survey with their associated UK parliamentary constituencies.

    To do so, I am under the impression I need to use the packages, "shp2dta" and "geoinpoly".

    I've obtained the constituency shapefile here:
    https://geoportal.statistics.gov.uk/...2c2ebeab92c0_2

    I then went about converting it into a .dta format using shp2dta using the follwing command:
    Code:
    shp2dta using Westminster_Parliamentary_Constituencies__December_2017__Boundaries_UK.shp,
    database(A) coordinates(COORD) genid(ID)
    This in turn produces a coordinates file. However, this is where the problems start to arise. The coordinates given are generic (x,y) coordinates - they are not geographic coordinates per se. If you plot them in a twoway graph they will still produce what looks like a map of the UK, however they are not in (lat, long) format

    This creates a promblem when I try to match my list of survey coordinates, with the UK parliamentary data. When I run the command which I hoped would work but obviously doesn't - i.e. the following:
    Code:
    geoinpoly lat long using coordinates
    It reutrns the obvious error:
    Y (latitude) must be between -90 and 90 in coordinates file
    Is there something I'm missing? Or can anyone suggest a creative work around which might alleviate this problem?

  • #2
    I had a similar issue once. As a workaround, I opened the shapefile in QGIS and resaved it using a lat/lon coordinates system.

    Try what's suggested here
    https://gis.stackexchange.com/questi...ude-using-qgis

    Comment


    • #3
      For those who might come across this while trying to resolve a similar problem, the issue is to do with the projection system used by the UK government.

      Their shapefiles seem to be mostly saved in British National Grid format. If you haven't already, you'll have to download QGIS and convert the coordinates there.

      Right click the layer -> Export->Save Feature As -> Set the CRS to default -> Save as a shapefile -> Go to Stata and use shp2dta

      Comment


      • #4
        Posting this in case anyone is having issues with the Irish version of this problem and is struggling to find any resources on it - thank you Andrew for posting your solution.

        I recently had the exact same issue with Irish government shapefiles downloaded from the Tailte Éireann open data portal. In my case, I was using shp2dta on the ungeneralised CSO Electoral Divisions shapefile, but I imagine the issue is the same for the other shapefiles. In the Irish case, the shapefiles use the Irish Transverse Mercator (IRENET95), but I followed Andrew's process exactly as outlined and it worked perfectly.

        Comment

        Working...
        X