I have two shapefiles, one points and the other one polygons. These two layers should overlay without any points being outside of boundary. Unfortunately, there were some points that were outside and the reason was that the points had incorrect latitude and longitude. I replaced them with correct latitude and longitude, however the points are still outside of boundary. I also changed Coordinate System to have the two layers use the same one (not sure if I did in right way). Even after changing the coordinate, I still have the problem. Below is a screenshot.
QGIS Shapefile Issues – Correcting Latitude and Longitude to Ensure Points Fall Within Boundaries
overlayqgisshapefile
Related Solutions
pseudocode for your problem would be:
for point1 in csv:
for point2 in csv:
distance = haversine(point1, point2)
where haversine is defined as (from e.g. https://gis.stackexchange.com/a/56589/15183) :
def haversine(lon1, lat1, lon2, lat2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees).
Source: https://gis.stackexchange.com/a/56589/15183
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
c = 2 * math.asin(math.sqrt(a))
km = 6367 * c
return km
...so the full code would be:
import csv
import math
def haversine(lon1, lat1, lon2, lat2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees).
Source: https://gis.stackexchange.com/a/56589/15183
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
c = 2 * math.asin(math.sqrt(a))
km = 6367 * c
return km
with open('1.csv', 'rb') as f1:
reader1 = csv.reader(f1, delimiter=';', quoting=csv.QUOTE_NONE)
header1 = reader1.next()
with open('2.csv', 'rb') as f2:
reader2 = csv.reader(f2, delimiter=';', quoting=csv.QUOTE_NONE)
header2 = reader2.next()
for row1 in reader1:
for row2 in reader2:
floats1 = map(float, row1[1:])
floats2 = map(float, row2[1:])
print(floats1)
print(floats2)
print haversine(floats1[1],floats1[0],floats2[1],floats2[0])
with the two files 1.csv:
name;lat;lon
NYC;40.58;-74.03
and 2.csv:
name;lat;lon
Cape Town;-33.90;18.46
...result checked against http://www.movable-type.co.uk/scripts/latlong.html seems correct.
You can either reproject your polygon shapefile OR your dataset. EPSG is a short code for spatial projections. EPSG:4326 is the code for non-projected data in degrees using wgs84: http://spatialreference.org/ref/epsg/4326/
Reproject your polygon into 4326
france_wgs84 <- spTransform(france_L93, CRS("+init=epsg:4326"))
Reproject your dataset into Lambert93
data <- structure(list(centerid = c("0121H1", "0121H2", "0218H3", "0303H1",
"0303H2"), latitude = c(46.2236804, 46.2236804, 49.3700842, 46.3429172,
46.3429172), longitude = c(5.2108193, 5.2108193, 3.335127, 2.6089958,
2.6089958), adresse_complete = c("900 Route de Paris, 01440 Viriat, France",
"900 Route de Paris, 01440 Viriat, France", "46 Avenue du Général de Gaulle, 02200 Soissons, France",
"18 Avenue du 8 Mai 1945, 03100 Montluçon, France", "18 Avenue du 8 Mai 1945, 03100 Montluçon, France"
)), .Names = c("centerid", "latitude", "longitude", "adresse_complete"
), row.names = c(NA, 5L), class = "data.frame")
coordinates(data) <- ~longitude+latitude
proj4string(data) <- "+init=epsg:4326"
data_L93 <- spTransform(data, CRS("+proj=lcc +lat_1=44 +lat_2=49 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +units=m
+no_defs"))
Best Answer
You can use the Vertex Tool to move a point by directly editing it's geometry values.
Put your layer in edit mode and activate the Vertex Tool:
You will now see the Vertex Editor panel widget docked on the left of the map canvas.
Now, when you right-click on a point you can edit the feature geometry's x and y values to move the point to a specific location.