Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support strings for spatial types creation #111

Closed
localusercamp opened this issue Feb 27, 2024 · 2 comments
Closed

Support strings for spatial types creation #111

localusercamp opened this issue Feb 27, 2024 · 2 comments

Comments

@localusercamp
Copy link

Hi, I just started using your package yesterday, so i may not understand something (do not blame me to hard =D).

I found that creating a new instance of MatanYadaev\EloquentSpatial\Objects\Point (or other spatial abstractions as well) is a bit of a mess (if your project big enough and you have a ton of spatial data manipulations).

Wouldn't it be nice to have string values support for creating models with spatial data types?

For example this code from your readme:

$vaticanCity = Place::create([
    'name' => 'Vatican City',
    'area' => new Polygon([
        new LineString([
              new Point(12.455363273620605, 41.90746728266806),
              new Point(12.450309991836548, 41.906636872349075),
              new Point(12.445632219314575, 41.90197359839437),
              new Point(12.447413206100464, 41.90027269624499),
              new Point(12.457906007766724, 41.90000118654431),
              new Point(12.458517551422117, 41.90281205461268),
              new Point(12.457584142684937, 41.903107507989986),
              new Point(12.457734346389769, 41.905918239316286),
              new Point(12.45572805404663, 41.90637337450963),
              new Point(12.455363273620605, 41.90746728266806),
        ]),
    ]),
])

Could be rewritten as such:

$vaticanCity = Place::create([
    'name' => 'Vatican City',
    'area' => new Polygon([
        new LineString([
              '12.455363273620605,41.90746728266806',
              '12.450309991836548,41.906636872349075',
              '12.445632219314575,41.90197359839437',
              '12.447413206100464,41.90027269624499',
              '12.457906007766724,41.90000118654431',
              '12.458517551422117,41.90281205461268',
              '12.457584142684937,41.903107507989986',
              '12.457734346389769,41.905918239316286',
              '12.45572805404663,41.90637337450963',
              '12.455363273620605,41.90746728266806',
        ]),
    ]),
])

Is it possible and what do you think about that?

@MatanYadaev
Copy link
Owner

You can use fromWkt or fromJson if you would like.

@localusercamp
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants