Community
Hello,
I would like to create a new layer based on the following fields :
Name (String) / Measure (Float) / the_geom (geometry)
I use the create_new_point_layer_definition.php example but I can't figure out how to insert the geometric field (from a Postgis database). The code looks like this :
// Create a feature class definition for the new feature source
$classDefinition = new MgClassDefinition();
$classDefinition->SetName("Point");
$classDefinition->SetDescription("Point");
$classDefinition->SetDefaultGeometryPropertyName("the_geom");
// Create an identify property
$identityProperty = new MgDataPropertyDefinition("KEY");
$identityProperty->SetDataType(MgPropertyType::Int32);
$identityProperty->SetAutoGeneration(true);
$identityProperty->SetReadOnly(true);
// Add the identity property to the class definition
$classDefinition->GetIdentityProperties()->Add($identityProperty);
$classDefinition->GetProperties()->Add($identityProperty);
// Create a name property
$nameProperty = new MgDataPropertyDefinition("Name");
$nameProperty->SetDataType(MgPropertyType::String);
// Add the name property to the class definition
$classDefinition->GetProperties()->Add($nameProperty);
// Create a measure property
$measureProperty = new MgDataPropertyDefinition("Measure");
$measureProperty->SetDataType(MgPropertyType::Float);
// Add the measure property to the class definition
$classDefinition->GetProperties()->Add($measureProperty);
// Create a geometry property
$geometryProperty = new MgGeometricPropertyDefinition("the_geom"); $geometryProperty->SetGeometryTypes(MgFeatureGeometricType::Point);
// Add the geometry property to the class definition
$classDefinition->GetProperties()->Add($geometryProperty);
// Create a feature schema
$featureSchema = new MgFeatureSchema("PointSchema", "Point schema");
// Add the feature schema to the class definition
$featureSchema->GetClasses()->Add($classDefinition);
// Create the feature source
$featureSourceName = 'Library://Data/points.FeatureSource';
$resourceIdentifier = new MgResourceIdentifier($featureSourceName);
$srs = $map->GetMapSRS();
$sdfParams = new MgCreateSdfParams("ArbitraryXY", $srs, $featureSchema); //Should I change something here ??
$featureService->CreateFeatureSource($resourceIdentifier, $sdfParams);
// We need to add some data to the sdf before using it. The spatial context
// reader must have an extent.
$batchPropertyCollection = new MgBatchPropertyCollection();
$wktReaderWriter = new MgWktReaderWriter();
$agfReaderWriter = new MgAgfReaderWriter();
$geometryFactory = new MgGeometryFactory();
// Make a point
$propertyCollection = ("Point A", 0.15, 01010000206A080000CAC9FA6B3C9129418E2E7FC632475841);
$batchPropertyCollection->Add($propertyCollection);
unset($propertyCollection);
I would appreciate any help on the subject !
Thanks a lot.
Cheers.