Being a newbie to GIS, I am trying to create a map using shapefiles and addresses found online, as an exercise. The steps are below:

  1. I downloaded a shapefile of Connecticut from the following link (Connecticut State House Districts; CT House Districts; 2010)
  2. I picked up a list of hospitals in Connecticut from this link
  3. I use the R script from this link to obtain a long/lat for each hospital
  4. I followed this discussion here to create a shapefile for hospitals; hospitals are presented as points
  5. I used QGIS to import the 2 shapefiles, the Connecticut boundary file, and the hospital location file

But I find that the hospitals are not located within Connecticut: the dots are displaced to other empty space, not on the Connecticut map.

I wonder if I missed anything when I was creating the shapefile for hospitals. Can anyone help? Thanks.

Below is my R-script for creating the hospital shapefile. I guess the CRS is the problem, but I'm not sure.

hosp.shp <- SpatialPointsDataFrame(coords=hosp.list[,c("coord_x","coord_y")],data=data.frame(hosp_name=hosp.list[,"hosp_name"]),proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))

writeOGR(hosp.shp,dsn="hosp_shp",layer="hosp_shp",driver="ESRI Shapefile")

update 01

I am using wgs84 version of Connecticut State House Districts, CT House Districts, 2010. I don't have specific reason to use this shp file, I just see this has quite a few of polygon, which may be easier for me to continue my GIS exercise.

Some elaboration on step 2. From the link, I have the names of quite a few of hospital, I used R to access google map to extract the long/lat for each hospital, e.g. "Advanced Center for Rehabilitation Medicine" has the long/lat of 41.1175966,-73.4078968.

I used google map to help me do the geocoding, and now I have a table with the name of the hospital, its long and lat. Then this table goes to step 3, using R again to produce a shp file. I import the self-made and the Connecticut shp file into QGIS, both layer can be show, and I can see the hospital seems to cluster to some location, but all of the hospitals are not located within the boundary of Connecticut, they are FAR away.

For the hospital shp file, I used CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"), which is copied direct from the Connecticut file, hoping that this will fix the "misalignment" problem, but no dice.

  • 1
    The Connecticut shapefile comes in several different versions within a single zip download. One of them uses a State Plane coordinate system. Perhaps you mistakenly have used that? (It's easy to check: look at the associated .prj file, which is human-readable.) Note, too, that the second discussion you reference is confused, because it uses lat-lon in the context of a question where the coordinates are clearly projected. – whuber Mar 2 '12 at 17:17
  • 4
    Also check that you assigned the lon/lat values in the correct order. the sample point is in lat, lon order. – mkennedy Mar 2 '12 at 19:55
  • 1
    Make sure you haven't mixed up longs and lats. The long. values should be x-coordinates, and lat. values y-coordinates. The "Advanced Center..." example above has a lat of 41.1175 and long of -73.407 – user3461 Mar 2 '12 at 19:59
  • I cannot reproduce this problem. Using the WGS84 version of the CT shapefile, I display it via library(maptools); ct <- readShapeSpatial("f:/temp/statect_37800_0000_2010_s100_census_1_shp_wgs84.shp"); plot(ct) and then add points as in x <- rnorm(10, mean=-73.408, sd=0.05); y <- rnorm(10, mean=41.118, sd=0.05); points(x,y). These cluster inside the southwestern corner of the state polygon. – whuber Mar 2 '12 at 21:30
  • 2
    thank mkenndey and Kevin, yes I swapped the lat/long – lokheart Mar 3 '12 at 2:56

Your Answer

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

Browse other questions tagged or ask your own question.