turash/bugulma/backend/internal/domain/geographical_feature.go
Damir Mukimov 0df4812c82
feat: Complete geographical features implementation with full test coverage
- Add comprehensive geographical data models (GeographicalFeature, TransportMode, TransportProfile, TransportOption)
- Implement geographical feature repository with PostGIS support and spatial queries
- Create transportation service for cost calculation and route optimization
- Build spatial resource matcher for geographical resource matching
- Develop environmental impact service for site environmental scoring
- Implement facility location optimizer with multi-criteria analysis
- Add geographical data migration service for SQLite to PostgreSQL migration
- Create database migrations for geographical features and site footprints
- Update geospatial service integration and server initialization
- Add CLI command for geographical data synchronization
- Implement complete test coverage for all geographical components (28 test cases)
- Update test infrastructure for geographical table creation and PostGIS handling

This implements advanced geospatial capabilities including transportation cost modeling, environmental impact assessment, and facility location optimization for the Turash platform.
2025-11-25 06:42:18 +01:00

102 lines
4.5 KiB
Go

package domain
import (
"context"
"time"
"gorm.io/datatypes"
)
// GeographicalFeatureType represents the type of geographical feature
type GeographicalFeatureType string
const (
GeographicalFeatureTypeRoad GeographicalFeatureType = "road"
GeographicalFeatureTypeGreenSpace GeographicalFeatureType = "green_space"
GeographicalFeatureTypePOI GeographicalFeatureType = "poi"
GeographicalFeatureTypeRailway GeographicalFeatureType = "railway"
GeographicalFeatureTypeWater GeographicalFeatureType = "water"
GeographicalFeatureTypeLandUse GeographicalFeatureType = "land_use"
)
// TransportMode represents different transportation methods
type TransportMode string
const (
TransportModeTruck TransportMode = "truck"
TransportModeRail TransportMode = "rail"
TransportModePipe TransportMode = "pipeline"
)
// TransportProfile defines transportation characteristics for different modes
type TransportProfile struct {
CostPerKm float64 `json:"cost_per_km"`
SpeedKmH float64 `json:"speed_km_h"`
MaxCapacity float64 `json:"max_capacity"`
EnvironmentalFactor float64 `json:"environmental_factor"` // Lower is better for environment
}
// TransportOption represents a transportation choice with cost analysis
type TransportOption struct {
TransportMode TransportMode `json:"transport_mode"`
DistanceKm float64 `json:"distance_km"`
CostEur float64 `json:"cost_eur"`
TimeHours float64 `json:"time_hours"`
EnvironmentalScore float64 `json:"environmental_score"`
CapacityUtilization float64 `json:"capacity_utilization_percent"`
OverallScore float64 `json:"overall_score"`
}
// GeographicalFeature represents geographical features like roads, green spaces, etc.
// imported from OpenStreetMap or other geospatial sources
type GeographicalFeature struct {
ID string `gorm:"primaryKey;type:text" json:"id"`
Name string `gorm:"type:text;index" json:"name"`
FeatureType GeographicalFeatureType `gorm:"type:varchar(50);not null;index" json:"feature_type"`
// Geometry (stored as PostGIS geometry, managed via raw SQL)
// The geometry column is managed separately via migrations
// It's excluded from GORM operations using raw SQL queries only
// OSM metadata
OSMType string `gorm:"type:varchar(50)" json:"osm_type"`
OSMID string `gorm:"type:varchar(50);index" json:"osm_id"`
// Properties from OSM or other sources
Properties datatypes.JSON `gorm:"type:jsonb" json:"properties"`
// Processing metadata
ProcessingVersion string `gorm:"type:varchar(20);default:'1.0'" json:"processing_version"`
QualityScore float64 `gorm:"type:double precision;default:0.0" json:"quality_score"`
Source string `gorm:"type:varchar(100);default:'osm'" json:"source"`
// Timestamps
CreatedAt time.Time `gorm:"autoCreateTime;index" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
}
// TableName specifies the table name for GORM
func (GeographicalFeature) TableName() string {
return "geographical_features"
}
// GeographicalFeatureRepository interface for geographical feature data access
type GeographicalFeatureRepository interface {
Create(ctx context.Context, feature *GeographicalFeature) error
GetByID(ctx context.Context, id string) (*GeographicalFeature, error)
GetByType(ctx context.Context, featureType GeographicalFeatureType) ([]*GeographicalFeature, error)
GetWithinBounds(ctx context.Context, minLat, minLng, maxLat, maxLng float64) ([]*GeographicalFeature, error)
GetIntersectingGeometry(ctx context.Context, wktGeometry string) ([]*GeographicalFeature, error)
GetByOSMID(ctx context.Context, osmType, osmID string) (*GeographicalFeature, error)
BulkCreate(ctx context.Context, features []*GeographicalFeature) error
Update(ctx context.Context, feature *GeographicalFeature) error
Delete(ctx context.Context, id string) error
GetAll(ctx context.Context) ([]*GeographicalFeature, error)
GetRoadsWithinRadius(ctx context.Context, lat, lng, radiusKm float64) ([]*GeographicalFeature, error)
GetGreenSpacesWithinRadius(ctx context.Context, lat, lng, radiusKm float64) ([]*GeographicalFeature, error)
GetTotalArea(ctx context.Context, featureType GeographicalFeatureType, minLat, minLng, maxLat, maxLng float64) (float64, error)
GetRoadNetworkStatistics(ctx context.Context) (map[string]interface{}, error)
Count(ctx context.Context) (int64, error)
CountByFeatureType(ctx context.Context) (map[GeographicalFeatureType]int64, error)
}