function CreatePolygon($coordinates) { $geometryFactory = new MgGeometryFactory(); $coordinateCollection = new MgCoordinateCollection(); $linearRingCollection = new MgLinearRingCollection(); for ($index = 0; $index < count($coordinates); ++$index) { $coordinate = $geometryFactory->CreateCoordinateXY(ParseLocaleDouble($coordinates[$index]), ParseLocaleDouble($coordinates[++$index])); $coordinateCollection->Add($coordinate); } $coordinateCollection->Add($geometryFactory->CreateCoordinateXY(ParseLocaleDouble($coordinates[0]), ParseLocaleDouble($coordinates[1]))); $linearRingCollection = $geometryFactory->CreateLinearRing($coordinateCollection); $captureBox = $geometryFactory->CreatePolygon($linearRingCollection, null); return $captureBox; }
private function CreatePolygonFromGeomText($geomText) { $geometryFactory = new MgGeometryFactory(); $vertices = explode(',', $geomText); $count = $vertices[0]; $coords = new MgCoordinateCollection(); for ($i = 0; $i < $count; $i++) { $coord = $geometryFactory->CreateCoordinateXY((double) $vertices[$i * 2 + 1], (double) $vertices[$i * 2 + 2]); $coords->Add($coord); } $linearRing = $geometryFactory->CreateLinearRing($coords); $polygon = $geometryFactory->CreatePolygon($linearRing, null); return $polygon; }
private function CreatePolygonFromGeomText($geomText) { $geometryFactory = new MgGeometryFactory(); $vertices = explode(',', $geomText); $count = $vertices[0]; $coords = new MgCoordinateCollection(); for ($i = 0; $i < $count; $i++) { $coord = $geometryFactory->CreateCoordinateXY((double) $vertices[($i * 2) + 1], (double) $vertices[($i * 2) + 2]); $coords->Add($coord); } //Some provider such as SQL Server Spatial, ODBC requires the polygon's start point must be the same as end point. if(($count>2) && (($coords->GetItem(0)->GetX() != $coords->GetItem($count-1)->GetX()) || ($coords->GetItem(0)->GetY() != $coords->GetItem($count-1)->GetY()))) { $coord = $geometryFactory->CreateCoordinateXY($coords->GetItem(0)->GetX(), $coords->GetItem(0)->GetY()); $coords->Add($coord); } $linearRing = $geometryFactory->CreateLinearRing($coords); $polygon = $geometryFactory->CreatePolygon($linearRing, null); return $polygon; }
function AddPolygon() { $geometryFactory = new MgGeometryFactory(); $agfWriter = new MgAgfReaderWriter(); $vertices = explode(',', $this->args['GEOMETRY']); $count = $vertices[0]; $coords = new MgCoordinateCollection(); for ($i = 0; $i < $count; $i++) { $coord = $geometryFactory->CreateCoordinateXY((double) $vertices[$i * 2 + 1], (double) $vertices[$i * 2 + 2]); $coords->Add($coord); } // Add the first vertex to make the ring close if ($count > 2) { $coord = $geometryFactory->CreateCoordinateXY((double) $vertices[1], (double) $vertices[2]); $coords->Add($coord); } $linearRing = $geometryFactory->CreateLinearRing($coords); $polygon = $geometryFactory->CreatePolygon($linearRing, null); $trans = $this->GetTransform(); if (null != $trans) { $polygon = $polygon->Transform($trans); } $byteReader = $agfWriter->Write($polygon); $propertyValues = new MgPropertyCollection(); $propertyValues->Add(new MgStringProperty('Text', $this->args['TEXT'])); $propertyValues->Add(new MgGeometryProperty('Geometry', $byteReader)); $this->InsertMarkupFeature($propertyValues); }
} //get kilometers if ($units == "ft") { $distance *= 3.2808399; } //get feet if ($units == "usft") { $distance *= 3.2808333; } //get US survey feet $total += $distance; //create the line string geometry representing this segment // $geomFactory = new MgGeometryFactory(); $coordinates = new MgCoordinateCollection(); $coordinates->Add($geomFactory->CreateCoordinateXY($x1, $y1)); $coordinates->Add($geomFactory->CreateCoordinateXY($x2, $y2)); $geom = $geomFactory->CreateLineString($coordinates); if ($segId == 1) { //first segment // if (!DataSourceExists($resourceSrvc, $dataSourceId)) { //create feature source // $classDef = new MgClassDefinition(); $classDef->SetName($featureName); $classDef->SetDescription(GetLocalizedString("MEASUREFEATURECLASS", $locale)); $classDef->SetDefaultGeometryPropertyName("GEOM"); //Set KEY property $prop = new MgDataPropertyDefinition("KEY"); $prop->SetDataType(MgPropertyType::Int32);