I am trying to create a "perfect" shapefile from the Excel data. "Perfect" means that it should match several factors: proper encoding and original data type.
Excel file basically contains information about point objects and includes five attributes with required types.
Attribute | Type | Description
--------------------------------------------------------------------------------
FFA_NR | integer | Object serial number
FFA_TXT | text | Object serial number but with leading zeros
Name | text | Object name
X | real | X-coordinate in Gauß-Krüger CS
Y | real | Y-coordinate in Gauß-Krüger CS
where an X,Y
-tuple is based on DHDN / 3-degree Gauß-Krüger zone 5 EPSG:31469
Data sample looks as following (demonstrated in the image below).
My workflow (similar to this Importing Spreadsheets or CSV files.) so far is
- In Excel,
Data > Save As...
- I am trying with
.xlsx
,.txt(MS-DOS)
or.csv(MS-DOS)
- In QGIS everything visualized nicely in the sense that it is placed correctly. I have done it with several approaches,
Layer > Add Layer > Add spreadsheet layer
andAdd Delimited Text Data
- Afterwards, in QGIS, I am saving the opened point layer as a shapefile with
Save vector layer as...
- Then in the Attribute table, I do have several issues with data encoding and data type
1. Data Type
When I import Excel data into QGIS I am partially losing my initial data types. For instance, instead of the desired 035
, I do have 35.
Obviously, it is about the import data type.
I have seen similar questions on this topic.
However, I can not understand how to create the file with .csvt
extension. What is the workflow? How to create it and where it should be stored?
Of course, in Attribute table I can create a new column, appropriated with a text type, and then proceed with a Filed Calculator, using for instance lpad("FAA_Nr", 3, '0')
.
2. Encoding
I am working with German text, that contains letters like ä, ö, ü, ß
. When in QGIS, I apply any of the encoding formats (System, UTF-8, ISO-8859-1, ISO-8859-15), none of my specific characters can be visualized.
Check the following graphics for UTF-8 and ISO-8859-15 accordingly.
I have found related topics,
However, I did not discover anything spectacular in the context of my issue. I am guessing that the problem is more with the Excel rather then QGIS, is not it?
Or maybe I apply the encode formatting on a wrong step. When should it be done?
Target: optimizing the efforts required for the data input in QGIS.
Answer
You can re-use existing csvt files. There is no invisible relation, "filename.csv" is connected by the base filename with type file "filename.csvt".
Save these files and make a test:
test.csv
001,002
test.csvt
"String","Integer"
Now run ogrinfo
ogrinfo test.csv -al
INFO: Open of `test.csv'
using driver `CSV' successful.
Layer name: test
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
field_1: String (0.0)
field_2: Integer (0.0)
OGRFeature(test):1
field_1 (String) = 001
field_2 (Integer) = 2
If you have file "test2.csv" with the same structure just copy or rename test.csvt into test2.csvt.
No comments:
Post a Comment