printf("Unable to open %s\n", $strfilename);
    return -1;
}
/* Loop through layers and dump their contents */
$numLayers = OGR_DS_GetLayerCount($hDatasource);
printf("\nLayers count = %s\n", $numLayers);
for ($i = 0; $i < $numLayers; $i++) {
    $hLayer = OGR_DS_GetLayer($hDatasource, $i);
    /* Dump info about this layer */
    $hLayerDefn = OGR_L_GetLayerDefn($hLayer);
    $numFields = OGR_FD_GetFieldCount($hLayerDefn);
    printf("\n===================\n");
    printf("Layer %d: '%s'\n\n", i, OGR_FD_GetName($hLayerDefn));
    for ($j = 0; $j < $numFields; $j++) {
        $hFieldDefn = OGR_FD_GetFieldDefn($hLayerDefn, $j);
        printf(" Field %d: %s (%s)\n", $j, OGR_Fld_GetNameRef($hFieldDefn), OGR_GetFieldTypeName(OGR_Fld_GetType($hFieldDefn)));
    }
    printf("\n");
    printf("Feature(s) count= %d", OGR_L_GetFeatureCount($hLayer, TRUE));
    printf("\n\n");
    /* And dump each feature individually */
    while (($hFeature = OGR_L_GetNextFeature($hLayer)) != NULL) {
        OGR_F_DumpReadable($hFeature);
        OGR_F_Destroy($hFeature);
    }
    printf("\n\n----- EOF -----\n");
    /* No need to free layer handle, it belongs to the datasource */
}
/* Close data source */
OGR_DS_Destroy($hDatasource);
?>
Example #2
0
 protected function insertSpecialFields($geoType, $dfnLayerDest, $dataLine)
 {
     // if "dataLine" contains point object
     if ($geoType == wkbPoint) {
         // we inform the name of representation
         for ($i = 0; $i < OGR_FD_GetFieldCount($dfnLayerDest); $i++) {
             $fieldDfn = OGR_FD_GetFieldDefn($dfnLayerDest, $i);
             if (OGR_Fld_GetNameRef($fieldDfn) == 'BlockName') {
                 OGR_F_SetFieldString($dataLine, $i, 'SQUARE');
             }
         }
     }
     return true;
 }
 function add_attributes_to_db($src_feature, $feature_id, $fk_col_name)
 {
     $success = false;
     $num_fields = OGR_F_GetFieldCount($src_feature);
     $sql_str = "INSERT INTO " . $this->attr_table_name . "(" . $fk_col_name . ", ";
     // append all field names to the
     // sql string first
     for ($i = 0; $i < $num_fields; $i++) {
         $field_defn = OGR_FD_GetFieldDefn(OGR_L_GetLayerDefn($this->ogr_src_layer), $i);
         $f_name = strtolower(OGR_Fld_GetNameRef($field_defn));
         $sql_str .= $f_name;
         if ($i < $num_fields - 1) {
             $sql_str .= ", ";
         }
     }
     $sql_str .= ") VALUES ( " . $feature_id . ", ";
     // append field values
     for ($i = 0; $i < $num_fields; $i++) {
         $field_defn = OGR_FD_GetFieldDefn(OGR_L_GetLayerDefn($this->ogr_src_layer), $i);
         $f_name = strtolower(OGR_Fld_GetNameRef($field_defn));
         $f_type = OGR_Fld_GetType($field_defn);
         $f_value = OGR_F_GetFieldAsString($src_feature, $i);
         // surround the value with quotes if
         // the type is string
         if ($f_type == OFTString) {
             $sql_str .= "'" . str_replace("'", "''", $f_value) . "'";
         } else {
             if ($f_value == "") {
                 $sql_str .= "NULL";
             } else {
                 $sql_str .= $f_value;
             }
         }
         if ($i < $num_fields - 1) {
             $sql_str .= ", ";
         }
     }
     $sql_str .= ")";
     $this->dbconn->connect();
     $result = pg_query($this->dbconn->conn, $sql_str);
     if (!$result) {
         echo "An error occurred while executing the query: " . $sql_str . pg_last_error($this->dbconn->conn) . "\n\n";
     } else {
         $success = true;
     }
     $this->dbconn->disconnect();
     return $success;
 }
     exit;
 }
 //$geometry = OGR_F_GetGeometryRef($feature);
 //$txt_buffer = "";
 //$res = OGR_G_ExportToWkt($geometry, $txt_buffer);
 //$res = OGR_G_GetGeometryName($geometry);
 //OGR_G_ExportToWkb($geometry, $txt_buffer);
 //OGR_G_ExportToWkb
 //$len = OGR_G_WkbSize($geometry);
 echo "feature: " . $txt_buffer . ", " . $res . "<br> ----- [fields] : ";
 //$field_defn = OGR_FD_GetFieldDefn( $feature, $i);
 $num_fields = OGR_F_GetFieldCount($dst_feature);
 for ($i = 0; $i < $num_fields; $i++) {
     //$field_defn = OGR_FD_GetFieldDefn( $feature_defn, $i);
     $field_defn = OGR_FD_GetFieldDefn($dst_feature_defn, $i);
     $f_name = strtolower(OGR_Fld_GetNameRef($field_defn));
     $f_type = OGR_Fld_GetType($field_defn);
     if ($f_type == OFTString) {
         $f_type = "string";
     } else {
         if ($f_type == OFTInteger) {
             $f_type = "int";
         } else {
             if ($f_type == OFTReal) {
                 $f_type = "double";
             } else {
                 $f_type = "unknown";
             }
         }
     }
     $f_value = OGR_F_GetFieldAsString($dst_feature, $i);