Example #1
0
 /**
  * Return layer definition string
  * reads either *.msl file with same base name as data file
  *   or default polygon/line/point.lyr file from plugin dir
  * @return string $layerString
  */
 protected function getLayerDefinition($connParams, $layerSpatialType)
 {
     $ogrDBConn = false;
     if ($connParams['type'] == "generic") {
         $ogrConnectionStr = $this->data_path_prefix . $connParams['layer'];
         //error_log($ogrConnectionStr);
         // $layerDefFile = dirname(__FILE__) . "/" . $connParams['layer'] . ".msl";   ## swap comment if layer definition file in plugin dir
         $layerDefFile = $ogrConnectionStr . ".msl";
     } else {
         $ogrConnectionStr = "PG: " . $connParams['connection'];
         $layerDefFile = dirname(__FILE__) . "/layerdefinition/" . $connParams['schema'] . "." . $connParams['layer'] . ".msl";
         //$layerDefFile = dirname(__FILE__) . "/layerdefinition/" . $connParams['layer'] . ".msl";
     }
     if ($layerSpatialType == "vector") {
         if (!file_exists($ogrConnectionStr) && $connParams['type'] == "generic") {
             error_log($ogrConnectionStr . " does not exist.");
             return null;
         }
         // Register all drivers
         OGRRegisterAll();
         // Open data source
         $hSFDriver = NULL;
         $hDatasource = OGROpen($ogrConnectionStr, 0, $hSFDriver);
         if (!$hDatasource) {
             error_log("Unable to open %s\n" . $ogrConnectionStr);
             return 0;
         }
         if ($connParams['type'] == "generic") {
             $hLayer = OGR_DS_GetLayer($hDatasource, 0);
         } else {
             $hLayer = OGR_DS_GetLayerByName($hDatasource, $connParams['schema'] . "." . $connParams['layer']);
         }
         /* Dump info about this layer */
         $hLayerDefn = OGR_L_GetLayerDefn($hLayer);
         $hFeature = OGR_L_GetNextFeature($hLayer);
         if (OGR_F_GetGeometryRef($hFeature) != NULL) {
             $hGeom = OGR_F_GetGeometryRef($hFeature);
             //$geomType = OGR_G_GetGeometryType($hGeom);
             $geomNameOGR = OGR_G_GetGeometryName($hGeom);
         }
         /* Close data source */
         OGR_DS_Destroy($hDatasource);
         /*$geomList[1] = "point";
           $geomList[2] = "line";
           $geomList[3] = "polygon";
           $geomList[6] = "polygon";*/
         $geomList["POINT"] = "point";
         $geomList["MULTIPOINT"] = "point";
         $geomList["LINESTRING"] = "line";
         $geomList["MULTILINESTRING"] = "line";
         $geomList["POLYGON"] = "polygon";
         $geomList["MULTIPOLYGON"] = "polygon";
         //            $geomName = $geomList[$geomType];
         $geomName = $geomList[$geomNameOGR];
     } else {
         $geomName = "raster";
     }
     if (is_file($layerDefFile)) {
         //if (is_file($layerDefFile = $layerFilename . ".msl")) {
         $layerString = file_get_contents($layerDefFile);
     } else {
         $layerPath = dirname(__FILE__) . "/layerdefinition/{$geomName}.lyr";
         $layerString = file_get_contents($layerPath);
     }
     //error_log("layerDefFile: $layerDefFile");
     return $layerString;
 }
 function get_geom_type($layer)
 {
     $feature = OGR_L_GetNextFeature($layer);
     $geometry = OGR_F_GetGeometryRef($feature);
     $geom_type = strtolower(OGR_G_GetGeometryName($geometry));
     $this->geom_type = $geom_type;
     return $geom_type;
 }
function DumpMultiPolygon($hGeom)
{
    /* -------------------------------------------------------------------- */
    /*      Build a list of strings containing the stuff for each ring.     */
    /* -------------------------------------------------------------------- */
    printf("%s:\n", OGR_G_GetGeometryName($hGeom));
    for ($iLine = 0; $iLine < OGR_G_GetGeometryCount($hGeom); $iLine++) {
        $hPolygon = OGR_G_GetGeometryRef($hGeom, $iLine);
        $eErr = DumpPolygon($hPolygon, &$strPolygon);
        if ($eErr != OGRERR_NONE) {
            return eErr;
        }
    }
    return OGRERR_NONE;
}
     exit;
 }
 echo "shapefile opened, postgres source opened";
 // shapefiles only have one layer, so
 // the second arg to GetLayer is 0.
 $src_layer = OGR_DS_GetLayer($src_ds, 0);
 if ($src_layer == NULL) {
     echo "could not open source layer";
     return;
 }
 $feature_defn = OGR_L_GetLayerDefn($src_layer);
 /*---------------------------------------------------------------------------------------*/
 /* this is done to find out the geometry type only - should be moved to its own function */
 $feature = OGR_L_GetNextFeature($src_layer);
 $geometry = OGR_F_GetGeometryRef($feature);
 $geom_type = strtolower(OGR_G_GetGeometryName($geometry));
 // execute sql command using form id to find out spatial table name and attribute table
 // namme
 $sql_str = "SELECT " . "tng_spatial_data.table_name, " . "tng_spatial_attribute_table.attr_table_name " . "FROM " . "tng_form_spatial_data " . "INNER JOIN tng_spatial_data ON tng_form_spatial_data.spatial_table_id = tng_spatial_data.spatial_table_id " . "INNER JOIN tng_spatial_attribute_table on tng_form_spatial_data.spatial_table_id = tng_spatial_attribute_table.spatial_table_id " . "WHERE " . "tng_form_spatial_data.form_id = 1 " . "AND " . "tng_spatial_data.geometry_type = '" . $geom_type . "'";
 $dbconn = new DBConn();
 $dbconn->connect();
 $result = pg_query($dbconn->conn, $sql_str);
 if (!$result) {
     echo "An error occurred while executing the query - class_form.php:47 " . pg_last_error($dbconn->conn);
     $dbconn->disconnect();
 } else {
     $dst_layer_name = pg_fetch_result($result, 0, 0);
     $dst_attr_table_name = pg_fetch_result($result, 0, 1);
     $dbconn->disconnect();
 }
 /* end find geometry type */