fix: Fix processing for vector attributres table
This commit is contained in:
@@ -58,12 +58,15 @@ func (c *GDALConverter) Footprint(ctx context.Context, src string) ([]byte, erro
|
||||
return info.Wgs84Extent, nil
|
||||
}
|
||||
|
||||
// VectorGeometry reads every feature of a vector file and returns their combined
|
||||
// geometry as a GeoJSON GeometryCollection reprojected to EPSG:4326, or nil if
|
||||
// the file has no features. The caller (PostGIS) dissolves the collection into
|
||||
// the union of all features. Zipped ESRI shapefiles are read in place via GDAL's
|
||||
// /vsizip/ virtual filesystem; GeoJSON and GeoPackage are read directly.
|
||||
func (c *GDALConverter) VectorGeometry(ctx context.Context, src string) ([]byte, error) {
|
||||
// VectorFeatures reads every feature of a vector file and returns their
|
||||
// geometries, reprojected to EPSG:4326, in file order (nil if the file has no
|
||||
// features). A feature with no geometry yields a nil entry at its index, so
|
||||
// the result stays aligned with attribute rows read from the same file (the
|
||||
// shapefile format itself has no other way to pair a .shp geometry record with
|
||||
// its .dbf attribute row than matching by position). Zipped ESRI shapefiles
|
||||
// are read in place via GDAL's /vsizip/ virtual filesystem; GeoJSON and
|
||||
// GeoPackage are read directly.
|
||||
func (c *GDALConverter) VectorFeatures(ctx context.Context, src string) ([]json.RawMessage, error) {
|
||||
input := src
|
||||
if strings.EqualFold(filepath.Ext(src), ".zip") {
|
||||
input = "/vsizip/" + src
|
||||
@@ -89,20 +92,16 @@ func (c *GDALConverter) VectorGeometry(ctx context.Context, src string) ([]byte,
|
||||
if err := json.Unmarshal(out, &fc); err != nil {
|
||||
return nil, fmt.Errorf("parse ogr2ogr output: %w", err)
|
||||
}
|
||||
|
||||
geoms := make([]json.RawMessage, 0, len(fc.Features))
|
||||
for _, f := range fc.Features {
|
||||
if len(f.Geometry) == 0 || string(f.Geometry) == "null" {
|
||||
continue
|
||||
}
|
||||
geoms = append(geoms, f.Geometry)
|
||||
}
|
||||
if len(geoms) == 0 {
|
||||
if len(fc.Features) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return json.Marshal(struct {
|
||||
Type string `json:"type"`
|
||||
Geometries []json.RawMessage `json:"geometries"`
|
||||
}{Type: "GeometryCollection", Geometries: geoms})
|
||||
geoms := make([]json.RawMessage, len(fc.Features))
|
||||
for i, f := range fc.Features {
|
||||
if len(f.Geometry) == 0 || string(f.Geometry) == "null" {
|
||||
continue
|
||||
}
|
||||
geoms[i] = f.Geometry
|
||||
}
|
||||
return geoms, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user