Coder Social home page Coder Social logo

Comments (9)

tmszi avatar tmszi commented on July 20, 2024 1

Shapefile e.g. hybas_lake_eu_lev01_v1c.shp DBF file contains column name ORDER which is reserved SQLite keyword, and it seems column is not properly escaped inside code during creating table.

  1. Download shapefiles e.g.
mkdir /tmp/shp && cd /tmp/shp && wget https://data.hydrosheds.org/file/hydrobasins/customized_with_lakes/hybas_lake_eu_lev01-12_v1c.zip
  1. Extract archive with cd /tmp/shp && unzip hybas_lake_eu_lev01-12_v1c.zip
  2. Try import some shapefile with
 v.in.ogr input=/tmp/shp/hybas_lake_eu_lev01_v1c.shp output=hybas_lake_eu_lev01_v1 project=test
  1. See error
GRASS nc_basic_spm_grass7/PERMANENT:~ > v.in.ogr input=/tmp/shp/hybas_lake_eu_lev01_v1c.shp output=hybas_lake_eu_lev01_v1 project=hybas
Project <hybas> created
Check if OGR layer <hybas_lake_eu_lev01_v1c> contains polygons...
 100%
Creating attribute table for layer <hybas_lake_eu_lev01_v1c>...
DBMI-SQLite driver error:
Error in sqlite3_prepare():
near "ORDER": syntax error

DBMI-SQLite driver error:
Error in sqlite3_prepare():
near "ORDER": syntax error

ERROR: Unable to create table: 'create table hybas_lake_eu_lev01_v1 (cat
       integer, HYBAS_ID integer, NEXT_DOWN integer, NEXT_SINK integer,
       MAIN_BAS integer, DIST_SINK double precision, DIST_MAIN double
       precision, SUB_AREA double precision, UP_AREA double precision,
       PFAF_ID integer, SIDE varchar ( 6 ), LAKE integer, ENDO integer,
       COAST integer, ORDER integer, SORT integer)'

from grass.

geografin avatar geografin commented on July 20, 2024

My principal question is: what is the classical proper way to import .shp files to preserve linking. My LOCATION serve as a database with some rasters and vectors that are always there (they are very big). My script imports any chosen watershed file and cuts big rasters and select vectors with this polygon. So I want to cleanly import and then remove working polygon without destructing the database.

from grass.

geografin avatar geografin commented on July 20, 2024

I think there are two problems described in one post, but I trust they come from the unique root. To be honest, I can't describe exactly the moment when the database looses the link.

from grass.

geografin avatar geografin commented on July 20, 2024

I tried again:

  1. Deleted all vector layers from LOCATION.
  2. Imported HydroLAKES vector without any settings from GUI on Windows as it is (successfully)
  3. Imported basin.shp without any settings as it is (with column FID).
  4. Deleted basin from LOCATION and exited from GUI.
  5. Run container.
  6. Run my script where v.in.ogr for basin vector without any settings and with overwrite
  7. Got errors:
Creating attribute table for layer <basin>...
DBMI-SQLite driver error:
Error in sqlite3_prepare():
table basin already exists

DBMI-SQLite driver error:
Error in sqlite3_prepare():
table basin already exists

ERROR: Unable to create table: 'create table basin (cat integer, FID
       integer)'
LAKE_AREA=5
BUFFER=10
WARNING: Coor file of vector map <basin@PERMANENT> is larger than it should
         be (18 bytes excess)
WARNING: East (7.90505033345994e-323) is not larger than West
         (6.95300572703085e-310)
ERROR: Illegal latitude for North: 7.32278e+25

Although db.tables didn't show any table for basin from GUI. That means I can properly import the file from GUI, but can't import it with the same command from linux terminal.
NB: I've deleted basin previously, where the table existing comes from?

from grass.

tmszi avatar tmszi commented on July 20, 2024

With this fix #3605 I successfully import shapefile from my comment above.

GRASS nc_basic_spm_grass7/PERMANENT:~ > v.in.ogr input=/tmp/shp/hybas_lake_eu_lev01_v1c.shp output=hybas_lake_eu_lev01_v1 project=hybas
Project <hybas> created
Check if OGR layer <hybas_lake_eu_lev01_v1c> contains polygons...
 100%
Creating attribute table for layer <hybas_lake_eu_lev01_v1c>...
Importing 1 features (OGR layer <hybas_lake_eu_lev01_v1c>)...
 100%
-----------------------------------------------------
Registering primitives...
-----------------------------------------------------
Cleaning polygons
-----------------------------------------------------
Breaking polygons...
Breaking polygons (pass 1: select break points)...
 100%
Breaking polygons (pass 2: break at selected points)...
 100%
-----------------------------------------------------
Removing duplicates...
 100%
-----------------------------------------------------
Breaking boundaries...
 100%
-----------------------------------------------------
Removing duplicates...
 100%
-----------------------------------------------------
Cleaning boundaries at nodes...
 100%
-----------------------------------------------------
Merging boundaries...
 100%
-----------------------------------------------------
Removing dangles...
 100%
-----------------------------------------------------
Building areas...
-----------------------------------------------------
Removing bridges...
 100%
-----------------------------------------------------
Registering primitives...
Building areas...
 100%
Attaching islands...
 100%
-----------------------------------------------------
Finding centroids for OGR layer <hybas_lake_eu_lev01_v1c>...
 100%
-----------------------------------------------------
Writing centroids...
 100%
-----------------------------------------------------
5193 input polygons
Total area: 1.8739E+13 (9466 areas)
Area without category: 4.66917E+11 (4273 areas)
-----------------------------------------------------
Copying features...
 100%
Building topology for vector map <hybas_lake_eu_lev01_v1@PERMANENT>...
Registering primitives...
Building areas...
 100%
Attaching islands...
 100%
Attaching centroids...
 100%

But it is not possible see attribute table data with GUI tool (error message is showed, because table column name is DB reserved keyword and is not escaped).

But with command db.select module it is possible query hybas_lake_eu_lev01_v1 table successfully:

GRASS hybas/PERMANENT:~ > db.tables
hybas_lake_eu_lev01_v1

GRASS hybas/PERMANENT:~ > db.select table=hybas_lake_eu_lev01_v1
cat|HYBAS_ID|NEXT_DOWN|NEXT_SINK|MAIN_BAS|DIST_SINK|DIST_MAIN|SUB_AREA|UP_AREA|PFAF_ID|SIDE|LAKE|ENDO|COAST|ORDER|SORT
1|2010000010|0|2010000010|2010000010|0|0|18236071.2|18236071|2|M|0|0|1|0|1

from grass.

geografin avatar geografin commented on July 20, 2024

The same error I got for basin2 file which is simply exported from HydroSHEDS basins, like @tmszi proposed.

Check if OGR layer <basin2> contains polygons...
 100%
Creating attribute table for layer <basin2>...
DBMI-SQLite driver error:
Error in sqlite3_prepare():
table basin already exists

DBMI-SQLite driver error:
Error in sqlite3_prepare():
table basin already exists

ERROR: Unable to create table: 'create table basin (cat integer, HYBAS_ID
       integer, NEXT_DOWN integer, NEXT_SINK integer, MAIN_BAS integer,
       DIST_SINK double precision, DIST_MAIN double precision, SUB_AREA
       double precision, UP_AREA double precision, PFAF_ID integer, SIDE
       varchar ( 6 ), LAKE integer, ENDO integer, COAST integer, ORDER
       integer, SORT integer)'
LAKE_AREA=5
BUFFER=10
WARNING: Coor file of vector map <basin@PERMANENT> is larger than it should
         be (18 bytes excess)
WARNING: East (7.90505033345994e-323) is not larger than West
         (6.95273213512812e-310)
ERROR: Illegal latitude for North: 7.32278e+25
ERROR: Illegal latitude for North: 192

Importing basin from such a full and clean file is preferrable.

from grass.

geografin avatar geografin commented on July 20, 2024

I haven't managed to load the table of HydroLAKES layer still.
The error with basin file seem to be corrected, but after basin had been loaded, the HydroLAKES table seem to loose the link again.

DBMI-SQLite driver error:
Error in sqlite3_prepare():
select * from HydroLAKES_polys_v10 where 0 = 1
no such table: HydroLAKES_polys_v10

DBMI-SQLite driver error:
Error in sqlite3_prepare():
select * from HydroLAKES_polys_v10 where 0 = 1
no such table: HydroLAKES_polys_v10

And by the way, yes, the basin shp was imported, but there is no features in the table, and the error is "Unable to open select cursor" when I try to display the attribute table.

from grass.

tmszi avatar tmszi commented on July 20, 2024

I haven't managed to load the table of HydroLAKES layer still. The error with basin file seem to be corrected, but after basin had been loaded, the HydroLAKES table seem to loose the link again.

DBMI-SQLite driver error:
Error in sqlite3_prepare():
select * from HydroLAKES_polys_v10 where 0 = 1
no such table: HydroLAKES_polys_v10

DBMI-SQLite driver error:
Error in sqlite3_prepare():
select * from HydroLAKES_polys_v10 where 0 = 1
no such table: HydroLAKES_polys_v10

And by the way, yes, the basin shp was imported, but there is no features in the table, and the error is "Unable to open select cursor" when I try to display the attribute table.

Could @geografin post exact reproducible steps, please (same as in my comment above #3604 (comment))?

from grass.

tmszi avatar tmszi commented on July 20, 2024

And by the way, yes, the basin shp was imported, but there is no features in the table, and the error is "Unable to open select cursor" when I try to display the attribute table.

Vector map attribute table (GUI tool) should be will open with this fix #3614 or use v.db.select or db.select inside emulator terminal. GUI tool require much more changes to work with attribute table which contains columns names with reserved DB backend keywords.

from grass.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.