0

I work for a small police department and we use crystal reports to build reports from our database. Our department has four patrol districts (the city divided into four parts). I am trying to build a query that will return incidents that occurred in one of the four districts. Currently our database has all the locations in a table with each location having a longitude / latitude.

I was wondering if there was a way to build a query using longitude / latitude to query locations only in one of the districts (areas)? Unfortunately the districts are not perfect squares. Any ideas?

  • 1
    Well, depending on what the quadrants look like, assuming four sides, you could fit four linear equations of the form a+bx=c to the outer boundaries of the quadrant, for each latitude and longitude, determine if it falls withing those boundaries. You could also use a "brute force" technique with a huge lookup table If lat>x and latx and long – TimSPQR Sep 26 '13 at 22:05
  • What database are you using? Databases vary alot in geospatial capabilities... – Twelfth Sep 26 '13 at 23:12
  • First question here is are the latitudes and longitudes dynamic in nature (or) static values that are stored in database. If those are static values and you know the values before building a query, I don't think it is difficult to write a query with latitudes and longitudes. Before that let me know how you get values for latitudes and longitudes – Siva Sep 27 '13 at 06:51
  • The latitude / longitude values are static and stored with each location. – Raymond Thomson Sep 27 '13 at 13:39
  • Also the district area would be a multisided polygon. – Raymond Thomson Sep 27 '13 at 13:39
  • In postgres, st_contains will work for you here (need PostGIS contribs installed). MSSQL has an equivlent : http://stackoverflow.com/questions/11054149/sql-server-2008-spatial-find-a-point-in-polygon and using oracle spatial here : http://stackoverflow.com/questions/4601202/geo-fence-how-to-find-if-a-point-or-a-shape-is-inside-a-polygon-using-oracle-sp I'm decently sure mysql has another option too. Each database has a slightly different way of handling these spatial 'in polygon' requests. – Twelfth Sep 27 '13 at 21:50
  • http://stackoverflow.com/questions/6541056/, http://stackoverflow.com/questions/15303568/,http://stackoverflow.com/questions/13772690/ – TimSPQR Sep 28 '13 at 11:53

0 Answers0