GeoIO.jl icon indicating copy to clipboard operation
GeoIO.jl copied to clipboard

Add `lenunit` option to `GeoIO.load`

Open kramsretlow opened this issue 1 year ago • 4 comments
trafficstars

I have an .obj file that was exported from a CAD program. The CAD software was using mm as the unit. If I import it as a SimpleMesh using GeoIO.load(filename).geometry, it comes out with units of meters. Is it (or could it be) possible to specify the units in the call to load? And/or, is there an easy way to change the units of a mesh after creation? Right now I am using the inelegant way of loading the mesh, then creating a new mesh with a fix_part_units function defined like this:

fix_unit(p) = Meshes.Point((ustrip.([coords(p).x, coords(p).y, coords(p).z]) .* u"mm")...)
fix_part_units(msh) = SimpleMesh([fix_unit(v) for v in vertices(msh)], msh.topology)

I've tried searching the docs and source, but I can't find the functionalities I'm after. Sorry if I've missed something.

I'm not familiar with all of the file formats, but I guess this point could apply to some other "unitless" formats as well.

kramsretlow avatar Jul 24 '24 01:07 kramsretlow

Hi @kramsretlow, it is good to see you.

We should probably add a lengthunit option to load as suggested given that .obj files don't store units.

Would you like to try adding the option yourself? You can forward it to any affected format, and we can review it.

juliohm avatar Jul 24 '24 10:07 juliohm

Hi @juliohm , thanks for remembering me 😄

I will try to make some time in the next while to work on it, though I can't promise it'll get done. So far I was still unable to find the point in the source where the meters unit magically joined my mesh coordinates--will need to check it more deeply.

I'm really enjoying using Meshes.jl for some computation job I'm doing on 3D parts. If one comes to Meshes.jl from a direction not related to geographical data, it feels slightly odd to need to go to GeoIO.jl (which is clearly geostats related) to load a mesh. Not a problem, but just a comment from user's perspective. In any case, thanks for your work on these packages!

kramsretlow avatar Jul 25 '24 00:07 kramsretlow

I was still unable to find the point in the source where the meters unit magically joined my mesh coordinates--will need to check it more deeply.

The units are added in the Point constructor. You can write Point(x, y) with x and y unitful quantities:

Point(1mm, 2mm)

m is the default unit when x and y are not unitful.

You can add a unit to a pre-existing tuple with:

u = mm

Point(x * u, y * u)

I'm really enjoying using Meshes.jl for some computation job I'm doing on 3D parts.

Glad you are enjoying it :)

If one comes to Meshes.jl from a direction not related to geographical data, it feels slightly odd to need to go to GeoIO.jl (which is clearly geostats related) to load a mesh. Not a problem, but just a comment from user's perspective. In any case, thanks for your work on these packages!

GeoIO.jl is not tied to GeoStats.jl (the package), but is certainly related to GeoStats.jl (the framework). It doesn't depend on the "stats" part of "geostats". Think of it as a simple tool to load geospatial data as geotables, which can be used for any purpose beyond geospatial data science and geostatistical modeling.

juliohm avatar Jul 25 '24 08:07 juliohm

@kramsretlow the option should be available now. Please update the environment.

I will leave the issue open because there some other formats also support the option, but we didn't have time to implement yet:

  • [x] vtk
  • [x] img
  • [x] csv

juliohm avatar Aug 09 '24 17:08 juliohm

/bounty $20

juliohm avatar Sep 09 '24 20:09 juliohm

💎 $20 bounty • JuliaEarth

Steps to solve:

  1. Start working: Comment /attempt #100 with your implementation plan
  2. Submit work: Create a pull request including /claim #100 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to JuliaEarth/GeoIO.jl!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🔴 @mobley-trent Sep 10, 2024, 6:11:33 AM WIP

algora-pbc[bot] avatar Sep 09 '24 20:09 algora-pbc[bot]

/attempt #100

Algora profile Completed bounties Tech Active attempts Options
@mobley-trent 10 bounties from 5 projects
Python, Rust,
Jupyter Notebook
Cancel attempt

mobley-trent avatar Sep 10 '24 06:09 mobley-trent

Hello @juliohm correct me if I'm wrong but this issue seems to have been fixed in #110

mobley-trent avatar Sep 10 '24 08:09 mobley-trent

@mobley-trent it is partially fixed. The option is not available in the formats listed above in a check list.

juliohm avatar Sep 10 '24 11:09 juliohm

I see that vtkread, imgread and csvread are referenced in the load function. Perhaps I am missing something @juliohm ?

mobley-trent avatar Sep 10 '24 11:09 mobley-trent

The option is passed to the inner functions, but it is being currently ignored. See the csvread for example:

https://github.com/JuliaEarth/GeoIO.jl/blob/8201229c6987924fb73ab49b3753b037d2ee1203/src/extra/csv.jl#L5

The option is not used inside the function.

juliohm avatar Sep 10 '24 12:09 juliohm

Fixed for all backends.

juliohm avatar Sep 24 '24 16:09 juliohm