CREATE TABLE gis_terms (
    id SERIAL PRIMARY KEY,
    term TEXT NOT NULL,
    slug TEXT UNIQUE NOT NULL,        -- for SEO URLs
    category TEXT,                    -- Optional: like "Vector", "Analysis", etc
    definition TEXT NOT NULL,
    synonyms TEXT[],                  -- ARRAY of strings
    related_terms TEXT[],             -- ARRAY of strings
    created_at TIMESTAMP DEFAULT now()
);


CREATE INDEX idx_terms_search ON gis_terms
USING GIN (to_tsvector('english', term || ' ' || definition));

 
CREATE EXTENSION IF NOT EXISTS pg_trgm;

SELECT term, similarity(term, 'topolgy') AS score
FROM gis_terms
WHERE term % 'topolgy'
ORDER BY score DESC;



SELECT * FROM gis_terms;


INSERT INTO gis_terms (term, slug, category, definition, synonyms, related_terms)
VALUES
(
    'Buffer',
    'buffer',
    'Analysis',
    'A zone around a geographic feature measured in units of distance or time.',
    ARRAY['proximity zone', 'buffer zone'],
    ARRAY['proximity analysis', 'overlay']
),
(
    'Topology',
    'topology',
    'Data Integrity',
    'A set of rules and behaviors that model how features share geometry.',
    ARRAY['connectivity rules', 'spatial relationship'],
    ARRAY['node', 'edge', 'polygon']
),
(
    'Raster',
    'raster',
    'Data Model',
    'A spatial data model that uses a grid of cells to represent spatial variation.',
    ARRAY['grid', 'pixel data'],
    ARRAY['DEM', 'satellite imagery']
);


ALTER TABLE gis_terms
ADD COLUMN term_ur TEXT,
ADD COLUMN definition_ur TEXT;


UPDATE gis_terms
SET term_ur = 'ٹاپولوجی',
    definition_ur = 'ٹاپولوجی وہ اصولی نظام ہے جو اشکال کے درمیان روابط اور حدود کو بیان کرتا ہے۔'
WHERE slug = 'topology';



INSERT INTO gis_terms (term, slug, category, definition, synonyms, related_terms)
VALUES  
('Absolute Coordinate Accuracy', 'absolute-coordinate-accuracy', 'Data Quality', 'The degree to which the location of a feature on a map corresponds to its true position on the earth.', ARRAY['geolocation accuracy', 'positional accuracy'], ARRAY['geodetic control', 'datum', 'surveying']),
('Access Route Mapping', 'access-route-mapping', 'Network Analysis', 'The process of identifying and mapping optimal paths or routes for accessibility.', ARRAY['route planning', 'travel path'], ARRAY['network dataset', 'connectivity', 'shortest path']),
('Accuracy Assessment Matrix', 'accuracy-assessment-matrix', 'Remote Sensing', 'A confusion matrix used to assess the accuracy of a classified image by comparing predicted vs actual values.', ARRAY['confusion matrix', 'error matrix'], ARRAY['classification', 'ground truth', 'validation']),
('Accumulated Catchment Area', 'accumulated-catchment-area', 'Hydrology', 'The total upstream area contributing flow to a specific point in a river or watershed.', ARRAY['upstream area', 'drainage area'], ARRAY['watershed', 'flow direction', 'basin']),
('Active Land Use Layer', 'active-land-use-layer', 'Urban Planning', 'A GIS layer showing currently utilized land types like residential, commercial, or industrial zones.', ARRAY['land utilization map', 'current land use'], ARRAY['LULC', 'zoning map', 'urban planning']),
('Activity Space Polygon', 'activity-space-polygon', 'Mobility Analysis', 'A polygon representing the geographic extent of a person’s routine movements or interactions.', ARRAY['travel footprint', 'daily activity area'], ARRAY['accessibility', 'mobility data', 'geolocation']),
('Adaptive Generalization', 'adaptive-generalization', 'Cartography', 'A method of simplifying map features based on scale and context without losing essential detail.', ARRAY['context-aware generalization', 'scale-dependent simplification'], ARRAY['map scale', 'topology preservation', 'feature simplification']),
('Address Mapping Service', 'address-mapping-service', 'Geocoding', 'An online or offline tool that converts addresses into spatial coordinates.', ARRAY['geocoding tool', 'address locator'], ARRAY['reverse geocoding', 'spatial database', 'locator engine']),
('Administrative Unit Code', 'administrative-unit-code', 'Census & Demographics', 'A standardized code assigned to administrative areas for statistical and mapping purposes.', ARRAY['admin code', 'govt area code'], ARRAY['district code', 'census unit', 'geographic ID']),
('Advanced Map Symbology', 'advanced-map-symbology', 'Cartography', 'Enhanced map symbol styles for better visual distinction of complex spatial data.', ARRAY['dynamic symbology', 'custom symbols'], ARRAY['legend design', 'data visualization', 'style rules']),
('Aerial Photogrammetric Layer', 'aerial-photogrammetric-layer', 'Remote Sensing', 'A GIS layer derived from aerial images using photogrammetric techniques for 3D modeling or mapping.', ARRAY['aerial stereo layer', 'photo-derived surface'], ARRAY['DSM', 'orthophoto', '3D mapping']),
('Agricultural Zoning Layer', 'agricultural-zoning-layer', 'Land Use Planning', 'A GIS layer defining areas designated for agriculture under zoning laws.', ARRAY['farming zones', 'agri land use'], ARRAY['zoning map', 'land classification', 'rural planning']),
('Airspace Control Boundary', 'airspace-control-boundary', 'Aviation GIS', 'A spatial boundary that defines regulated airspace zones for air traffic management.', ARRAY['airspace zone', 'flight boundary'], ARRAY['no-fly zone', 'air corridor', 'aviation map']),
('Alignment Topology Rule', 'alignment-topology-rule', 'Data Quality', 'A rule that ensures linear features like roads or pipelines are aligned at junctions.', ARRAY['connectivity rule', 'snapping constraint'], ARRAY['topology validation', 'editing rule', 'feature matching']),
('Allocation Weight Surface', 'allocation-weight-surface', 'Spatial Analysis', 'A raster surface showing weight values used in spatial allocation models or suitability analysis.', ARRAY['cost surface', 'weight raster'], ARRAY['MCDA', 'suitability model', 'land allocation']),
('Ambient GIS Noise Mapping', 'ambient-gis-noise-mapping', 'Environmental GIS', 'Mapping of ambient environmental noise levels using spatial data sources and sensors.', ARRAY['noise pollution map', 'sound level surface'], ARRAY['environmental analysis', 'sensor data', 'urban noise']),
('Analytical Influence Zone', 'analytical-influence-zone', 'Spatial Analysis', 'An area of spatial effect around a feature, used for impact or influence modeling.', ARRAY['buffer zone', 'impact area'], ARRAY['catchment', 'service area', 'distance decay']),
('Angular Parcel Orientation', 'angular-parcel-orientation', 'Cadastral GIS', 'The angular direction of a land parcel relative to north, used in cadastral mapping.', ARRAY['parcel bearing', 'plot angle'], ARRAY['cadastral data', 'boundary orientation', 'survey map']),
('Anthropogenic Land Use Layer', 'anthropogenic-land-use-layer', 'Land Use', 'A GIS layer showing land areas modified by human activity.', ARRAY['human-modified layer', 'built environment'], ARRAY['urban area', 'infrastructure', 'land cover']),
('API Spatial Wrapper', 'api-spatial-wrapper', 'Development', 'A programming wrapper or library for simplifying spatial API calls and data handling.', ARRAY['API bridge', 'spatial library'], ARRAY['GeoJSON API', 'REST GIS', 'SDK']),
('Apparent Slope Layer', 'apparent-slope-layer', 'Terrain Analysis', 'A raster showing slope values as perceived from a specific viewpoint or illumination angle.', ARRAY['visual slope', 'pseudo-slope'], ARRAY['hillshade', 'aspect map', 'terrain modeling']);
