Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3284608
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:10:24+00:00 2026-05-17T20:10:24+00:00

I have two tables one called Point and other called Poly i have around

  • 0

I have two tables one called Point and other called Poly i have around 400 polygons in the Poly table and around 200 thousand points in Point table. what i wanted is to find how many points are there in a certain polygon. The query i am using is:

select COUNT(*) from point p
inner join Poly pl  on pl.GeoDataID = 101 and p.geopoint.STIntersects(pl.Poly)=1 

I have also created Spatial Indexes on both GeoPoint and Poly Columns and both columns are geography type.

Edit:Using SQL Server 2008

Question: Above query returns results in around 1 min to 40 secs that is too slow for my case because i wanted to show them on Google Maps on real time. Is my approach for this problem is right? or it there any better way to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:10:25+00:00Added an answer on May 17, 2026 at 8:10 pm

    First check your spatial indexes. You can create them using a SQL statement such as

    CREATE SPATIAL INDEX MyIndexName ON MyTable(GeomFieldName) USING GEOMETRY_GRID
    WITH (
    BOUNDING_BOX =(-1493907.5664457313, 6128509.51667404, -578861.3521250226, 7703103.135644257),
    GRIDS =(LEVEL_1 = MEDIUM,LEVEL_2 = MEDIUM,LEVEL_3 = MEDIUM,LEVEL_4 = MEDIUM),
    CELLS_PER_OBJECT = 16, PAD_INDEX  = OFF, SORT_IN_TEMPDB = OFF,
    DROP_EXISTING = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON)
    

    A key parameter to change is the BOUNDING_BOX. This should be set to the bounding box of your data, or maximum bounding box of expected data. So if your data is restricted to North America, set the bounding box to the extent of North America rather than the world.

    You can add calculated fields to show the bound of each feature as noted at http://geographika.co.uk/sql-server-spatial-sql – and can then use a standard query to see the maximum extents.

    Also check using profiler to see that the indexes are actually being used. Sometimes you have to force their use with the WITH (INDEX (MyIndexName)) statement.

    SELECT *
    FROM MyTable
    WITH (INDEX (MyIndexName))
    WHERE (geometry::Point(@x,@y,3785).STWithin(MyGeomField) = 1)
    

    I have also found that sometimes it is quicker when querying by points not to use a spatial index, so it is worth experimenting.

    Alternatives

    A final option would be to create a trigger when a new record is added that would assign it a polygon ID when it is created or updated. This would allow almost instant queries on your data.

    And Finally

    In the latest Denali SQL Server release spatial indexes can be created with an auto option rather than manually. There has apparently also been a performance boost for STWithin and STIntersects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables one has a three column composite key. The other needs
I have a one to many relationship between two tables. The many table contains
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables, one stores the products and quantity we have bought, the
I have two tables with the same columns, and I need to copy one
Lets say I have two tables - child and parent with many-to-one relation. What
I have two tables, we'll call them Foo and Bar , with a one
I have two mysql tables, one containing details on cars and one containing all
I have two fields in a table. One contains values such as BTA, BEA,
I have two tables that are joined together. A has many B Normally you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.