Giter VIP home page Giter VIP logo

Comments (4)

mbloch avatar mbloch commented on May 27, 2024

Hi!

The syntax of the web console and the command line are slightly different. You can run "history" in the web console to translate your console commands to their command line equivalents, but you'll probably have to change the paths of the input files, because the web console doesn't know where on your computer the input files came from.

I can see that keys='[latitude,longitude],gasht_name' in your example is wrong. The keys option is used when joining two layers by matching data values in so-called "key" fields. I think you want to do a different kind of join, called a spatial join, which doesn't use the keys option.

I think the solution will look more like this:

mapshaper -i Tabriz_houses_inf.csv \
-points \
-join  codgashttabriz.json fields=gasht_name \
-o output.geojson

Good luck!

from mapshaper.

Roostaei110 avatar Roostaei110 commented on May 27, 2024

Hi @mbloch, thank you for your attention. Here are the steps I followed:

Step One: Running history in the web console:

mapshaper -i codgashttabriz.shp
-i Tabriz_houses_inf.csv
-points x=longitude y=latitude
-target codgashttabriz
-proj wgs84
-clip codgashttabriz
-join codgashttabriz target='Tabriz_houses_inf' fields='gasht_name'
-o target= format=dsv

Step Two: Writing in a python file:
mapshaper_commands = [
["mapshaper", "-i", shp_file],
["mapshaper", "-i", csv_file],
["mapshaper", csv_file, "-points", "x=longitude", "y=latitude"],
["mapshaper", shp_file, "-target", shp_file[:-4]],
["mapshaper", shp_file, "-proj", "wgs84"],
["mapshaper", csv_file, "-clip", shp_file[:-4]],
["mapshaper", '-join', shp_file[:-4], f'target={csv_file[:-4]}', 'fields=gasht_name'],
["mapshaper", csv_file, "-target", csv_file[:-4], '-o', 'target= format=dsv']
]

for line in mapshaper_commands:
subprocess.run(line)

The output is:

[i] Auto-detected number fields: code, unit_price, unit_price_En, elevator, parking, warehouse, meterage, latitude, longitude
[i] Auto-detected number fields: code, unit_price, unit_price_En, elevator, parking, warehouse, meterage, latitude, longitude
[points] 2,402 of 3,586 points are null
[wkt] unhandled parameter: Auxiliary_Sphere_Type
[i] Auto-detected number fields: code, unit_price, unit_price_En, elevator, parking, warehouse, meterage, latitude, longitude
Error: [clip] File not found (codgashttabriz)
Run mapshaper -h to view help
Error: [join] Missing layer: Tabriz_houses_inf
Run mapshaper -h to view help
[i] Auto-detected number fields: code, unit_price, unit_price_En, elevator, parking, warehouse, meterage, latitude, longitude
Error: [o] Missing layer: format=dsv
Run mapshaper -h to view help

Step Three: I changed line ["mapshaper", csv_file, "-clip", shp_file[:-4]] to ["mapshaper", csv_file, "-clip", shp_file] , which resolved the related error. The output is as:

[i] Auto-detected number fields: code, unit_price, unit_price_En, elevator, parking, warehouse, meterage, latitude, longitude
[i] Auto-detected number fields: code, unit_price, unit_price_En, elevator, parking, warehouse, meterage, latitude, longitude
[points] 2,402 of 3,586 points are null
[wkt] unhandled parameter: Auxiliary_Sphere_Type
[i] Auto-detected number fields: code, unit_price, unit_price_En, elevator, parking, warehouse, meterage, latitude, longitude
[wkt] unhandled parameter: Auxiliary_Sphere_Type
Error: [join] Missing layer: Tabriz_houses_inf
Run mapshaper -h to view help
[i] Auto-detected number fields: code, unit_price, unit_price_En, elevator, parking, warehouse, meterage, latitude, longitude
Error: [o] Missing layer: format=dsv
Run mapshaper -h to view help

Step Four: I encountered issues with the join command not recognizing Tabriz_houses_inf or Tabriz_houses_inf.csv. I tried changing the line related to join as ["mapshaper", '-join', shp_file[:-4], f'target={csv_file}', 'fields=gasht_name'], but I received the following error:

Error: [join] Missing layer: Tabriz_houses_inf.csv
Run mapshaper -h to view help
[i] Auto-detected number fields: code, unit_price, unit_price_En, elevator, parking, warehouse, meterage, latitude, longitude
Error: [o] Missing layer: format=dsv

I'm unsure about the last two lines and how to resolve them. I apologize for the lengthy text. I wanted to provide all the necessary details.

from mapshaper.

mbloch avatar mbloch commented on May 27, 2024

I suggest first getting your sequence of commands to work in an interactive shell, like bash. I gave you a set of shell commands to try in my earlier comment. Once you have something like that working, then you can port it to Python.

Your process has multiple steps -- I often start simple, with one editing command followed by a -o or -info command to check that the result is what I want. Then I add more commands until I have an entire pipeline of commands.

The first problem I see with your Python script is that you are splitting up your work into multiple subprocesses. The entire sequence of mapshaper commands should be contained in a single Python subprocess. Otherwise the results from one command will not be passed on to the next command. Files are not modified unless they are overwritten using the -o command.

from mapshaper.

Roostaei110 avatar Roostaei110 commented on May 27, 2024

You were right @mbloch, I should have written everything in one command. My problem is solved. I really enjoyed mapshaper.

from mapshaper.

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.