Veltris
MENU
  • Company
      • AboutusAbout Us
      • __CSR_mainCSR
      • LeadershipLeadership
      • __Life at Veltris-mainLife at Veltris
      • ChannelPartnerships
      • Contact usContact Us
      • pressroom-01Pressroom
      • EventsEvents
  • AI Services
    • __Digital & Cloud_1AI-Augmented Engineering
    • __Data & AI_1AI Readiness & Data
      Modernization
    • __Connectivity & Industry X.0_1 (1)AI Monetization
    • __Product Lifecyle & Managed Services_1Product Lifecycle &
      Managed Services
  • Industries
    • HealthcareHealthcare
      • __Health TechHealthTech & MedTech Platforms
      • __Dental CareDental & Multi-Unit Retail Health
      • __Pharmacy Benefit Management (PBM)Pharmacy Benefit Management (PBM)
    • Hi TechTechnology
      • __Technology Products & PlatformsSoftware / XTech / AI Platforms
      • __Communications Service ProvidersSecure Networking & Infrastructure
    • __Diversified IndustrialsIndustrials
      • __Autonomous Vehicles and LogisticsIndustrial & Mobility Tech
      • __Engineering and ConstructionEngineering & Construction Tech
  • Insights
    • BlogsBlogs
    • White papersWhitepapers
    • Glossary-svgAI Guides and Innovations
    • CasestudiesClient Case Studies
  • Careers
  • Vertical AI Platform
    (VeltrisOneā„¢)
Get My AI Readiness Score
Veltris
Vertical AI Platform
  • Company
    • About Us
    • Leadership
    • Partnerships
    • Pressroom
    • Events
    • CSR
    • Life at Veltris
    • Contact Us
  • AI Services
    • AI-Augmented Engineering
    • AI Readiness & Data
      Modernization
    • AI Monetization
    • Product Lifecycle & Managed Services
  • Industries
    • Healthcare
      • HealthTech & MedTech Platforms
      • Dental & Multi-Unit Retail Health
      • Pharmacy Benefit Management (PBM)
    • Technology
      • Software / XTech / AI Platforms
      • Secure Networking & Infrastructure
    • Industrials
      • Industrial & Mobility Tech
      • Engineering & Construction Tech
  • Insights
    • Blogs
    • Whitepapers
    • AI Guides and Innovations
    • Client Case Studies
  • Careers
  • Vertical AI Platform
    (VeltrisOneā„¢)
Blogs

GIS on Rails

July 5, 2019 | Team Veltris
  • Blogs
  • Product Lifecycle & Managed Services
  • Technology, Communications & Media

Dealing with Geospatial data is cumbersome and at the same time, it is fun. Developers who do it for the first time might enter some road blockers but as you progress it gives a joy of learning. GIS stands for Geographic information system which deals with gathering, mapping and analyzing geospatial data. But it is not as easy as it sounds. Let me walk through you the challenges that I have faced recently in my project:

Requirement: Import existing polygons information and map that given latitude and longitude with the polygon.

Challenge-1: Understanding the basics and jargon

Since I am doing for the first time, like what SRID should I use, what datatype should I use, what coordinate system should I use? After thorough research I end up using srid 4326, multipolygon datatype and WGS 84 coordinate system.

Many of you might not understand what WGS 84 means? WGS 84 stands for World Geodetic System is kind of survey (standard) which was done on the year 1984. There are different kinds of standards that are exists currently like WGS 72, WGS 66 and WGS 60 etc. These are the surveys(standards) that are conducted in those respective years by making some assumptions about earth. So, for example if we calculate India location using WGS 84 is might be different if we calculate using WGS 72.

SRID stands for Spatial Reference System Identifier which tells us about the coordinate system we were using while gathering spatial data.

Challenge-2: Data importing

Since we are using rails powered with postgresql, importing data into database is quite easy but not in this case as we got information in geojsonformat which I never seen before. Fortunately, ruby provides a gem called rgeo-json which makes our life easy. Following is the code snippet that I have written to import geojson data.

@geo_factory = RGeo::Geographic.spherical_factory(srid: 4326)f = RGeo::GeoJSON.decode(
File.open(<geojson file path>).read,
geo_factory: @geo_factory)
)
f.each do
polygon
Polygon.new(geopolygon: polygon.geometry).save
end

where polygon is our model. Here is our migration file looks like:

add_column :polygons, :geopolygon, :multi_polygon, srid: 4326 

Challenge-3: Map point with Polygon using sql query

PostGIS is a postgres database extension which enables postgres to make spatial calculations. To find that given point lies which polygon we need to make use of st_contains function. To use st_contains, first we have to make sure whether two geometries should use same SRID or not ie., in our case it is 4326. Since in my database we are storing latitude and longitude as float columns, first we need to typecast them to as a POINT and set SRID to 4326 as follows:

# Returns geometry of a given point.
ST_SetSRID(ST_POINT(<longitude>, <latitude>), 4326)

Now final query to find appropriate polygon:

Polygon.where("st_contains(geopolygon, 
ST_SetSRID(ST_Point(<long>,<lat>), 4326)
) = true").first

Though it took time to complete requirement but at the end I felt I have done something different than what I usually do. I hope this article would throw some light about GIS.

Original Source: https://medium.com/@learnitnow/gis-on-rails-23513c15de7c

FOUND THIS USEFUL? SHARE WITH

Related Articles

RCM Automation: The Path to Faster Claim Cycles, Fewer Denials, and Stronger Cash Flow
AIOps: Enhancing Banking Core Systems Reliability and Transactions Availability
AIOps Self-Healing for Investment Management Platform Stability & Growth
AI-Enhanced Modernization: Revitalizing Legacy Trading and Wealth Management Platforms
The Connected Cure: Exploring the Potential of IoMT Ecosystems
Navigating the Future of Healthcare: Top 6 Technology Trends for 2025 and Beyond
Veltris
Company
  • About Us
  • Leadership
  • Partnerships
  • Pressroom
  • Events
  • CSR
  • Life at Veltris
  • Contact Us
  • Careers
Services
  • Digital & Cloud Engineering
  • Data & AI
  • Connectivity & Industry X.0
  • Product Lifecycle & Managed Services
Industries
  • Healthcare & Lifesciences
  • Communications & Media
  • Diversified Industrials & Manufacturing
  • Financial & PubSec Services
AI Solutions
  • AI Solutions Overview
  • AI for Productivity
  • AI for Industry
  • AI for Enterprise
Insights
  • Blogs
  • Whitepapers
  • AI Guides and Innovations
  • Client Case Studies
Copyright © 2026 Veltris. All Rights Reserved.
Cookie Policy | Disclaimer | Privacy Policy | Sitemap
Veltris
  • About Us
  • Leadership
  • Partnerships
  • Pressroom
  • Events
  • CSR
  • Life at Veltris
  • Contact Us
  • Careers
  • Digital & Cloud Engineering
  • Data & AI
  • Connectivity & Industry X.0
  • Product Lifecycle & Managed Services
  • Healthcare & Lifesciences
  • Communications & Media
  • Diversified Industrials & Manufacturing
  • Financial & PubSec Services
  • AI Solutions Overview
  • AI for Productivity
  • AI for Industry
  • AI for Enterprise
  • Blogs
  • Whitepapers
  • AI Guides and Innovations
  • Client Case Studies
Copyright © 2026 Veltris. All Rights Reserved.
Cookie Policy | Disclaimer | Privacy Policy | Sitemap