Importing CSV file to create point layer
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I have a CSV file with following fields:
- Nodename
- Nodeid
- Latitude
- Longtitude
- Elevation
I am using Python console in QGIS to automate this. How should I write so that point with latitude, longtitude and elevation are maked as point layer?
I have tried with below code, but I am getting error.
uri = "/home/priti/Desktop/MTP work/nodeinput.csv?
type=csv&xField=Longtitude
&yField=Lattitude
&spatialIndex=no&subsetIndex=no&watchFile=no"
vlayer = QgsVectorLayer(uri, 'Nodes', "delimitedtext")
qgis python pyqgis csv
 |Â
show 2 more comments
up vote
1
down vote
favorite
I have a CSV file with following fields:
- Nodename
- Nodeid
- Latitude
- Longtitude
- Elevation
I am using Python console in QGIS to automate this. How should I write so that point with latitude, longtitude and elevation are maked as point layer?
I have tried with below code, but I am getting error.
uri = "/home/priti/Desktop/MTP work/nodeinput.csv?
type=csv&xField=Longtitude
&yField=Lattitude
&spatialIndex=no&subsetIndex=no&watchFile=no"
vlayer = QgsVectorLayer(uri, 'Nodes', "delimitedtext")
qgis python pyqgis csv
What error message do you get?
â BERA
Aug 21 at 10:10
SyntaxError: EOL while scanning string literal
â ps1
Aug 21 at 10:13
If you screenshot is showing what you are doing of course it will not work. You need to change path to file+filename and the name of lat and long field
â BERA
Aug 21 at 11:04
I didnt get you .
â ps1
Aug 21 at 11:06
I am woking on Ubuntu system . There is no such C drive here i think
â ps1
Aug 21 at 11:08
 |Â
show 2 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a CSV file with following fields:
- Nodename
- Nodeid
- Latitude
- Longtitude
- Elevation
I am using Python console in QGIS to automate this. How should I write so that point with latitude, longtitude and elevation are maked as point layer?
I have tried with below code, but I am getting error.
uri = "/home/priti/Desktop/MTP work/nodeinput.csv?
type=csv&xField=Longtitude
&yField=Lattitude
&spatialIndex=no&subsetIndex=no&watchFile=no"
vlayer = QgsVectorLayer(uri, 'Nodes', "delimitedtext")
qgis python pyqgis csv
I have a CSV file with following fields:
- Nodename
- Nodeid
- Latitude
- Longtitude
- Elevation
I am using Python console in QGIS to automate this. How should I write so that point with latitude, longtitude and elevation are maked as point layer?
I have tried with below code, but I am getting error.
uri = "/home/priti/Desktop/MTP work/nodeinput.csv?
type=csv&xField=Longtitude
&yField=Lattitude
&spatialIndex=no&subsetIndex=no&watchFile=no"
vlayer = QgsVectorLayer(uri, 'Nodes', "delimitedtext")
qgis python pyqgis csv
qgis python pyqgis csv
edited Aug 21 at 11:01
asked Aug 21 at 9:42
ps1
1319
1319
What error message do you get?
â BERA
Aug 21 at 10:10
SyntaxError: EOL while scanning string literal
â ps1
Aug 21 at 10:13
If you screenshot is showing what you are doing of course it will not work. You need to change path to file+filename and the name of lat and long field
â BERA
Aug 21 at 11:04
I didnt get you .
â ps1
Aug 21 at 11:06
I am woking on Ubuntu system . There is no such C drive here i think
â ps1
Aug 21 at 11:08
 |Â
show 2 more comments
What error message do you get?
â BERA
Aug 21 at 10:10
SyntaxError: EOL while scanning string literal
â ps1
Aug 21 at 10:13
If you screenshot is showing what you are doing of course it will not work. You need to change path to file+filename and the name of lat and long field
â BERA
Aug 21 at 11:04
I didnt get you .
â ps1
Aug 21 at 11:06
I am woking on Ubuntu system . There is no such C drive here i think
â ps1
Aug 21 at 11:08
What error message do you get?
â BERA
Aug 21 at 10:10
What error message do you get?
â BERA
Aug 21 at 10:10
SyntaxError: EOL while scanning string literal
â ps1
Aug 21 at 10:13
SyntaxError: EOL while scanning string literal
â ps1
Aug 21 at 10:13
If you screenshot is showing what you are doing of course it will not work. You need to change path to file+filename and the name of lat and long field
â BERA
Aug 21 at 11:04
If you screenshot is showing what you are doing of course it will not work. You need to change path to file+filename and the name of lat and long field
â BERA
Aug 21 at 11:04
I didnt get you .
â ps1
Aug 21 at 11:06
I didnt get you .
â ps1
Aug 21 at 11:06
I am woking on Ubuntu system . There is no such C drive here i think
â ps1
Aug 21 at 11:08
I am woking on Ubuntu system . There is no such C drive here i think
â ps1
Aug 21 at 11:08
 |Â
show 2 more comments
3 Answers
3
active
oldest
votes
up vote
3
down vote
accepted
Try:
from qgis.core import QgsMapLayerRegistry #Qgis2
#from qgis.core import QgsProject #QGIS3
uri = "file:///C:/Test/points.csv?delimiter=,&crs=epsg:4326&xField=Longitude&yField=Latitude"
vlayer = QgsVectorLayer(uri,'Points','delimitedtext')
QgsMapLayerRegistry.instance().addMapLayer(vlayer) #Qgis2
#QgsProject.instance().addMapLayer(vlayer) #QGIS3
QgsProject' object has no attribute 'addMapLayer' Getting this Error
â ps1
Aug 21 at 10:22
Yeah This time there was no error, but i cant see points
â ps1
Aug 21 at 10:30
any idea ? why i cant see points :(
â ps1
Aug 21 at 10:37
Do you get the 'Points' layer in Layers tree? Is the attribute table empty?
â BERA
Aug 21 at 10:39
My Layer Panel is empty
â ps1
Aug 21 at 10:41
 |Â
show 7 more comments
up vote
1
down vote
You say you are trying with the python console, but if you want to try with stand alone python, this does the trick:
import fiona
from shapely.geometry import Point, mapping
import csv
driver = 'ESRI Shapefile'
schema = 'geometry': 'Point', 'properties' : 'Nodename': 'str', 'Nodeid': 'int'
pointlayer = fiona.open("test.shp", 'w', driver=driver, schema=schema)
with open("test.csv") as f:
reader = csv.reader(f)
next(reader) # skip header
for row in reader:
geom = Point(int(row[2]), int(row[3]), int(row[4])) # Considering the order of elements that you gave
pointlayer.write('geometry': mapping(geom), 'properties': 'Nodename': row[0], 'Nodeid': row[1])
pointlayer.close()
add a comment |Â
up vote
0
down vote
Skip QGIS and go directly to OGR2OGR.
https://www.gdal.org/drv_csv.html
use -lco X_POSSIBLE_NAMES="" -lco Y_POSSIBLE_NAMES=
ogr2ogr airports.shp airports.csv -dialect sqlite -sql "SELECT MakePoint(CAST(longitude as REAL), CAST(latitude as REAL), 4326) Geometry, * FROM airports"
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Try:
from qgis.core import QgsMapLayerRegistry #Qgis2
#from qgis.core import QgsProject #QGIS3
uri = "file:///C:/Test/points.csv?delimiter=,&crs=epsg:4326&xField=Longitude&yField=Latitude"
vlayer = QgsVectorLayer(uri,'Points','delimitedtext')
QgsMapLayerRegistry.instance().addMapLayer(vlayer) #Qgis2
#QgsProject.instance().addMapLayer(vlayer) #QGIS3
QgsProject' object has no attribute 'addMapLayer' Getting this Error
â ps1
Aug 21 at 10:22
Yeah This time there was no error, but i cant see points
â ps1
Aug 21 at 10:30
any idea ? why i cant see points :(
â ps1
Aug 21 at 10:37
Do you get the 'Points' layer in Layers tree? Is the attribute table empty?
â BERA
Aug 21 at 10:39
My Layer Panel is empty
â ps1
Aug 21 at 10:41
 |Â
show 7 more comments
up vote
3
down vote
accepted
Try:
from qgis.core import QgsMapLayerRegistry #Qgis2
#from qgis.core import QgsProject #QGIS3
uri = "file:///C:/Test/points.csv?delimiter=,&crs=epsg:4326&xField=Longitude&yField=Latitude"
vlayer = QgsVectorLayer(uri,'Points','delimitedtext')
QgsMapLayerRegistry.instance().addMapLayer(vlayer) #Qgis2
#QgsProject.instance().addMapLayer(vlayer) #QGIS3
QgsProject' object has no attribute 'addMapLayer' Getting this Error
â ps1
Aug 21 at 10:22
Yeah This time there was no error, but i cant see points
â ps1
Aug 21 at 10:30
any idea ? why i cant see points :(
â ps1
Aug 21 at 10:37
Do you get the 'Points' layer in Layers tree? Is the attribute table empty?
â BERA
Aug 21 at 10:39
My Layer Panel is empty
â ps1
Aug 21 at 10:41
 |Â
show 7 more comments
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Try:
from qgis.core import QgsMapLayerRegistry #Qgis2
#from qgis.core import QgsProject #QGIS3
uri = "file:///C:/Test/points.csv?delimiter=,&crs=epsg:4326&xField=Longitude&yField=Latitude"
vlayer = QgsVectorLayer(uri,'Points','delimitedtext')
QgsMapLayerRegistry.instance().addMapLayer(vlayer) #Qgis2
#QgsProject.instance().addMapLayer(vlayer) #QGIS3
Try:
from qgis.core import QgsMapLayerRegistry #Qgis2
#from qgis.core import QgsProject #QGIS3
uri = "file:///C:/Test/points.csv?delimiter=,&crs=epsg:4326&xField=Longitude&yField=Latitude"
vlayer = QgsVectorLayer(uri,'Points','delimitedtext')
QgsMapLayerRegistry.instance().addMapLayer(vlayer) #Qgis2
#QgsProject.instance().addMapLayer(vlayer) #QGIS3
edited Aug 21 at 10:32
answered Aug 21 at 10:20
BERA
11.7k41537
11.7k41537
QgsProject' object has no attribute 'addMapLayer' Getting this Error
â ps1
Aug 21 at 10:22
Yeah This time there was no error, but i cant see points
â ps1
Aug 21 at 10:30
any idea ? why i cant see points :(
â ps1
Aug 21 at 10:37
Do you get the 'Points' layer in Layers tree? Is the attribute table empty?
â BERA
Aug 21 at 10:39
My Layer Panel is empty
â ps1
Aug 21 at 10:41
 |Â
show 7 more comments
QgsProject' object has no attribute 'addMapLayer' Getting this Error
â ps1
Aug 21 at 10:22
Yeah This time there was no error, but i cant see points
â ps1
Aug 21 at 10:30
any idea ? why i cant see points :(
â ps1
Aug 21 at 10:37
Do you get the 'Points' layer in Layers tree? Is the attribute table empty?
â BERA
Aug 21 at 10:39
My Layer Panel is empty
â ps1
Aug 21 at 10:41
QgsProject' object has no attribute 'addMapLayer' Getting this Error
â ps1
Aug 21 at 10:22
QgsProject' object has no attribute 'addMapLayer' Getting this Error
â ps1
Aug 21 at 10:22
Yeah This time there was no error, but i cant see points
â ps1
Aug 21 at 10:30
Yeah This time there was no error, but i cant see points
â ps1
Aug 21 at 10:30
any idea ? why i cant see points :(
â ps1
Aug 21 at 10:37
any idea ? why i cant see points :(
â ps1
Aug 21 at 10:37
Do you get the 'Points' layer in Layers tree? Is the attribute table empty?
â BERA
Aug 21 at 10:39
Do you get the 'Points' layer in Layers tree? Is the attribute table empty?
â BERA
Aug 21 at 10:39
My Layer Panel is empty
â ps1
Aug 21 at 10:41
My Layer Panel is empty
â ps1
Aug 21 at 10:41
 |Â
show 7 more comments
up vote
1
down vote
You say you are trying with the python console, but if you want to try with stand alone python, this does the trick:
import fiona
from shapely.geometry import Point, mapping
import csv
driver = 'ESRI Shapefile'
schema = 'geometry': 'Point', 'properties' : 'Nodename': 'str', 'Nodeid': 'int'
pointlayer = fiona.open("test.shp", 'w', driver=driver, schema=schema)
with open("test.csv") as f:
reader = csv.reader(f)
next(reader) # skip header
for row in reader:
geom = Point(int(row[2]), int(row[3]), int(row[4])) # Considering the order of elements that you gave
pointlayer.write('geometry': mapping(geom), 'properties': 'Nodename': row[0], 'Nodeid': row[1])
pointlayer.close()
add a comment |Â
up vote
1
down vote
You say you are trying with the python console, but if you want to try with stand alone python, this does the trick:
import fiona
from shapely.geometry import Point, mapping
import csv
driver = 'ESRI Shapefile'
schema = 'geometry': 'Point', 'properties' : 'Nodename': 'str', 'Nodeid': 'int'
pointlayer = fiona.open("test.shp", 'w', driver=driver, schema=schema)
with open("test.csv") as f:
reader = csv.reader(f)
next(reader) # skip header
for row in reader:
geom = Point(int(row[2]), int(row[3]), int(row[4])) # Considering the order of elements that you gave
pointlayer.write('geometry': mapping(geom), 'properties': 'Nodename': row[0], 'Nodeid': row[1])
pointlayer.close()
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You say you are trying with the python console, but if you want to try with stand alone python, this does the trick:
import fiona
from shapely.geometry import Point, mapping
import csv
driver = 'ESRI Shapefile'
schema = 'geometry': 'Point', 'properties' : 'Nodename': 'str', 'Nodeid': 'int'
pointlayer = fiona.open("test.shp", 'w', driver=driver, schema=schema)
with open("test.csv") as f:
reader = csv.reader(f)
next(reader) # skip header
for row in reader:
geom = Point(int(row[2]), int(row[3]), int(row[4])) # Considering the order of elements that you gave
pointlayer.write('geometry': mapping(geom), 'properties': 'Nodename': row[0], 'Nodeid': row[1])
pointlayer.close()
You say you are trying with the python console, but if you want to try with stand alone python, this does the trick:
import fiona
from shapely.geometry import Point, mapping
import csv
driver = 'ESRI Shapefile'
schema = 'geometry': 'Point', 'properties' : 'Nodename': 'str', 'Nodeid': 'int'
pointlayer = fiona.open("test.shp", 'w', driver=driver, schema=schema)
with open("test.csv") as f:
reader = csv.reader(f)
next(reader) # skip header
for row in reader:
geom = Point(int(row[2]), int(row[3]), int(row[4])) # Considering the order of elements that you gave
pointlayer.write('geometry': mapping(geom), 'properties': 'Nodename': row[0], 'Nodeid': row[1])
pointlayer.close()
answered Aug 21 at 10:24
ImanolUr
19212
19212
add a comment |Â
add a comment |Â
up vote
0
down vote
Skip QGIS and go directly to OGR2OGR.
https://www.gdal.org/drv_csv.html
use -lco X_POSSIBLE_NAMES="" -lco Y_POSSIBLE_NAMES=
ogr2ogr airports.shp airports.csv -dialect sqlite -sql "SELECT MakePoint(CAST(longitude as REAL), CAST(latitude as REAL), 4326) Geometry, * FROM airports"
add a comment |Â
up vote
0
down vote
Skip QGIS and go directly to OGR2OGR.
https://www.gdal.org/drv_csv.html
use -lco X_POSSIBLE_NAMES="" -lco Y_POSSIBLE_NAMES=
ogr2ogr airports.shp airports.csv -dialect sqlite -sql "SELECT MakePoint(CAST(longitude as REAL), CAST(latitude as REAL), 4326) Geometry, * FROM airports"
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Skip QGIS and go directly to OGR2OGR.
https://www.gdal.org/drv_csv.html
use -lco X_POSSIBLE_NAMES="" -lco Y_POSSIBLE_NAMES=
ogr2ogr airports.shp airports.csv -dialect sqlite -sql "SELECT MakePoint(CAST(longitude as REAL), CAST(latitude as REAL), 4326) Geometry, * FROM airports"
Skip QGIS and go directly to OGR2OGR.
https://www.gdal.org/drv_csv.html
use -lco X_POSSIBLE_NAMES="" -lco Y_POSSIBLE_NAMES=
ogr2ogr airports.shp airports.csv -dialect sqlite -sql "SELECT MakePoint(CAST(longitude as REAL), CAST(latitude as REAL), 4326) Geometry, * FROM airports"
answered Aug 21 at 15:08
Geospatial Engineer
56014
56014
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f293469%2fimporting-csv-file-to-create-point-layer%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What error message do you get?
â BERA
Aug 21 at 10:10
SyntaxError: EOL while scanning string literal
â ps1
Aug 21 at 10:13
If you screenshot is showing what you are doing of course it will not work. You need to change path to file+filename and the name of lat and long field
â BERA
Aug 21 at 11:04
I didnt get you .
â ps1
Aug 21 at 11:06
I am woking on Ubuntu system . There is no such C drive here i think
â ps1
Aug 21 at 11:08