Locations within bounds #51
-
Hello, First of all, great library. Really helped me get started on this small map project I'm on. I'm saving coordinates of an 'Address' like so:
I use a factory function to see a whole bunch of points:
Great so far, but now I would like to retrieve points within a certain bounds:
Is there a way to do this? Sorry for the really base question... |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Hey there, thanks for the kind words :) |
Beta Was this translation helpful? Give feedback.
-
Regarding your question: |
Beta Was this translation helpful? Give feedback.
-
In a project we extended Faker with a Geometry Provider like this: In <?php
namespace Database\Factories\FakerProvider;
use Clickbar\Magellan\Data\Geometries\LineString;
use Clickbar\Magellan\Data\Geometries\Point;
use Clickbar\Magellan\Data\Geometries\Polygon;
class GeometryProvider extends \Faker\Provider\Base
{
private static $frankfurt_latitude_bounds = [
'min' => 50.079492,
'max' => 50.141190,
];
private static $frankfurt_longitude_bounds = [
'min' => 8.634186,
'max' => 8.730392,
];
public function randomLatitude(): float
{
return self::randomFloat(
min: self::$frankfurt_latitude_bounds['min'],
max: self::$frankfurt_latitude_bounds['max']
);
}
public function randomLongitude(): float
{
return self::randomFloat(
min: self::$frankfurt_longitude_bounds['min'],
max: self::$frankfurt_longitude_bounds['max']
);
}
public function randomPoint(int $ssrid = 4326): Point
{
return Point::make($this->randomLongitude(), $this->randomLatitude(), null, null, $ssrid);
}
} Then in public function boot(): void
{
// ...
fake()->addProvider(new \Database\Factories\FakerProvider\GeometryProvider(fake()));
// ...
} So you could then use in your factory: return [
'geometry' => fake()->randomPoint(),
// ...
]; This should put you on the right track to make a bouding box specific faker point. :) |
Beta Was this translation helpful? Give feedback.
-
We just released a new update which allows using Box2D and Box3D as params for MagellanExpressions. Address::stWhere(ST::contains(Box2D::make(1,1,1,1), 'geometry'))->get(); Depending on the SRID set in the Database, this can lead to an Database Error. If your point in the database has SRID=4326: This can be avoided by setting an SRID: Address::stWhere(
ST::contains(
ST::setSRID(Box2D::make(1, 1, 1, 1), 4326),
'geometry'
)
)->get();
|
Beta Was this translation helpful? Give feedback.
We just released a new update which allows using Box2D and Box3D as params for MagellanExpressions.
So you can now do the following:
Depending on the SRID set in the Database, this can lead to an Database Error.
e.g.
If your point in the database has SRID=4326:
Internal error: 7 ERROR: contains: Operation on mixed SRID geometries (Point, 0) != (Point, 4326)
This can be avoided by setting an SRID: