1. Go to this page and download the library: Download hular369/geo-shapify library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hular369 / geo-shapify example snippets
Note: currently the feature is available only for 'norway', 'sweden', 'finland', 'denmark', 'germany', 'lithuania', 'nepal'.
// Create a polygon shape
$drawCountry = ShapeFactory::create('sweden');
// Check if a point is inside the polygon
$isInside = $drawCountry->contains(56.701853, 12.319418);
// Calculate the area of the polygon
$area = $drawCountry->area();
// get nearest vertex of the polygon
$nearestVertex = $drawCountry->nearestVertex(57.322011, 11.229478)
// Define the coordinates of the polygon vertices
$egpt = [
[31.597741, 25.112545],
[22.152357, 24.958816],
[22.081148, 36.719048],
[31.269823, 31.338550]
];
// Create a polygon shape
$drawShape = ShapeFactory::create('polygon', $egpt);
// Check if a point is inside the polygon
$isInside = $drawShape->contains(27.701853, 85.319418);
// Calculate the area of the polygon
$area = $drawShape->area();
// get nearest vertex of the polygon
$nearestVertex = $drawShape->nearestVertex(27.701853, 85.319418)
// Output the results
echo "Nearest vertex of the polygon: " . json_encode($nearestVertex) . PHP_EOL;
echo "Is inside: " . ($isInside ? "Yes" : "No") . PHP_EOL;
echo "Area: " . $area . PHP_EOL;
// Create a ShapeFactory instance
$shape = new ShapeFactory();
// Create a circle shape with center coordinates and radius
$drawShape = $shape::create('circle', null, 27.710258, 85.279664, 10); // radius=10 in km
// Check if a point is inside the circle
$isInside = $drawShape->contains(27.710258, 85.279664);
// Calculate the area of the circle
$area = $drawShape->area(); // area in sq. km
// Output the results
echo "Is inside: " . ($isInside ? "Yes" : "No") . PHP_EOL;
echo "Area: " . $area . PHP_EOL;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.