unicef / magicbox-latlon-admin-server

API that takes latitude/longitude pairs and returns an ID and metadata for the administrative boundaries they're located within
BSD 3-Clause "New" or "Revised" License
1 stars 2 forks source link

Batch example return error #2

Closed xmnlab closed 6 years ago

xmnlab commented 6 years ago

Dear all,

I am trying to test the batch example, but the server return this:

[{"error":{"message":"No results"}},{"error":{"message":"No results"}}]

The all_countries_one_table table has 0 rows .. Is that expected? The spatial_ref_sys table has 5435 rows.

Any idea about how to resolve this problem?

mikefab commented 6 years ago

Hi @xmnlab, This may not be clear in the readme: Prior to running the server, you have to download all shapefiles from gadm.org, and then import the shapefiles to postgres. If you like, we can skype and I'll demonstrate.

xmnlab commented 6 years ago

Hi @mikefab

yes, I did it before to use coordinates_to_admin_id_server

download library seems to work fine.

There are one folder for each country at download_shapefiles_from_gadm/data/shapefiles/gadm2-8

The folders download_shapefiles_from_gadm and import_shapefiles_to_postgres/ are in the same folder.

this is my conf.js file (import):

module.exports = {
    shapefile_dir: '../download_shapefiles_from_gadm/data/shapefiles/',
    pg_config: {
      database: 'all_countries_one_table',
      user: 'unicef', //env var: PGUSER
      password: 'unicef', //env var: PGPASSWORD
      host: 'localhost', // Server hosting the postgres database
      port: 5432, //env var: PGPORT
      max: 10, // max number of clients in the pool
      idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed
    },

}

After the installation, I call the package as mentioned in the documentation:

node main.js -s gadm2-8

To work better I create a postgres user with the same name as my linux user and configure its authentication method in postgresql configuration as peer (as postgres user).

local   all             myusername                                     peer

After I call the package (as mentioned before), the result is like this:

...

ZWE !!!!
bash lib/create_db_all_countries_one_table.sh all_countries_one_table zwe_2_gadm2-8 ../download_shapefiles_from_gadm/data/shapefiles/gadm2-8/ZWE/ZWE_adm2.shp
Table exists all_countries_one_table

Done with import of admins.
...

The all_countries_one_table database is created with two tables: all_countries_one_table and spatial_ref_sys ... but all_countries_one_table table is empty. There are 5435 rows at spatial_ref_sys table.

mikefab commented 6 years ago

To test locally, I just dropped the all_countries_one_database db and ran: node main.js -s gadm2-8.

screen shot 2017-12-19 at 5 58 30 pm I stopped it after running a few countries, and then logged into postgres: screen shot 2017-12-19 at 5 57 04 pm

Looking back at my code, I realize I could have designed it better. Let me know if this helps. Also happy to screenshare on skype with you to see it live.

mikefab commented 6 years ago

Also, to give you an idea of what's going on, the script begins by creating the db, and then scans all the country shapefiles to get a list of every column. Then it creates a table with those columns, and proceeds to append each shapefile.

Please see if this works from root of import_shapefiles_to_postgres: node ./lib/get_all_geo_property_fields

I get... screen shot 2017-12-19 at 6 16 54 pm

xmnlab commented 6 years ago

@mikefab

thank you for your attention!

I found the problem ... I format my laptop some months ago and I "lost" the postgis ..

I installed it again and now I think it will work.

Thank you so much