{
  "id": "2003-novemberdecember-geometry-scripting-find-nearby-points",
  "slug": "2003-novemberdecember-geometry-scripting-find-nearby-points",
  "url": "https://dwillis.github.io/uplink/article/2003-novemberdecember-geometry-scripting-find-nearby-points.html",
  "year": 2003,
  "month": "November/December",
  "monthNum": 11,
  "headline": "Geometry, scripting find nearby points",
  "kicker": "Tech tip",
  "author_name": "Brad Heath",
  "author_title": "",
  "affiliation": "The Detroit News",
  "summary": "A guide to using GIS software (ArcView 3.2) and its Avenue scripting language to analyze the spatial relationship between convicted sex offenders and day-care centers, specifically to determine how many offenders live within a mile of each facility and measure distances using coordinate geometry.",
  "keywords": [
    "GIS",
    "geocoding",
    "coordinates"
  ],
  "topics": [
    "Technology",
    "Investigative Methods"
  ],
  "technologies": [
    "ArcView",
    "Avenue",
    "Access"
  ],
  "full_text": "Your state is pondering a new law: No convicted sex offenders should live within a mile of a day-care center. But what's the context? To find out, you need to answer two questions: How many sex offenders actually live near each day-care center in your neighborhood and, for each one, exactly how far away is the nearest offender?\n\nYou know how to start answering these questions using your geographic information system (GIS) program - I used ESRI ArcView 3.2. You've already used geocoding to turn a data table of day-care center street addresses in your community into a point map, and did the same for a table of convicted sex offenders. So now all you have to do is count up which ones are near each other.\n\nHow?\n\nThat's where it gets interesting.\n\nArcView will need to go through and check each day-care center for the closest sex offender. And it will have to count how many offender points are within a mile of each center. That's simple to do by hand if you're only looking at one or two facilities. But what if you're looking at dozens, or thousands?\n\nArcView doesn't come with that ability. You have to build it yourself using ArcView's scripting language, called Avenue. Once you learn Avenue you can make ArcView do pretty much anything.\n\nIn this case, it's using coordinate geometry. To answer the questions, you'll need to fill out both themes with accurate X and y coordinates. Then you can use scripts or queries to search through the data to figure out which sex offenders are closest to the day-care centers.\n\nStep one is creating the coordinates. If you have a point theme in ArcView, odds are you're dealing in latitude and longitude - decimal degrees. While these are flexible, they aren't the best for measuring distance, so you need to put some coordinates in your data.\n\nStart by changing the projection of your view. Switch to the NAD 1983 projection for your state plane. (These projections are built in to ArcView 3.x.) Also, change the distance and map units to feet. Then open the attributes table for the theme you want to work on first. Start editing it and add two fields: \"ProjX\" and \"ProjY\". Set them up as numeric and be sure to allow for several decimal places. Close the table but don't hit the \"Stop Editing\" button yet.\n\nNow you're ready to add some coordinates. To do it, you'll need an Avenue script that cycles through each record and retrieves the X and y coordinates that correspond to the map projection you've chosen. The code looks like this:\n\ncurView = av.GetProject. FindDoc(\"mymap\"\nthmToUpdate = curView.FindTheme(\"shp\")\ntabToUpdate = thmToUpdate.GetFTab\nprjView = curView.GetProjection\n\nfldShape = tabToUpdate.FindField(\"Shape\")\nfldProjX = tabToUpdate.FindField(\"projx\")\nfldProjY = FindField\n\nfor each rec in tabToUpdate\n\ncurRect = tabToUpdate.ReturnValue(fldShape, rec)\n\nProjX = curRec.ReturnProjected(prjView).GetX\nProjY = curRec.ReturnProjected(prjView).GetY\n\ntabToUpdate.SetValue(fldProjX, rec, ProjX)\ntabToUpdate.SetValue(fldProjY, rec, ProjY)\n\nend\n\nAfter you enter the code, make sure you update it with the name of your view and theme. Then compile it with the checkmark icon and run it.\n\nNow back to your table. Look at the ProjX and ProjY fields and they should be filled in with numbers - the eastings and northings of your point. Instead of using latitude and longitude, these coordinates identify a point based on how many feet north and east it is from a predefined point on the map. Click \"Stop Editing\" and save the results. Then export the table you just finished and repeat the process for your second table. Import both into Access.\n\nThis leaves you with a database, two tables that lack a common field for joining. But Microsoft Access and other database managers will let you use more sophisticated relationships.\n\nInstead of using a join, you can link the points in the two tables using the Pythagorean distance formula, which can calculate the distance between any two points on a plane using their coordinates.\n\nHere's how you'd use Access SQL to link the tables based upon points that are at most a mile (5,280 feet) apart:\n\nWHERE sqr((((daycare.ProjX - offenders.ProjX)^2)+(daycare.ProjY- offenders.ProjY)^2)) <= 5280\n\nNow you can insert that into a SQL statement to answer the two questions.\n\nFirst: How many sex offenders live within a mile of each day-care center? You'll want a query that will check the data and count every point where the distance is less than 5,280 feet. Here's the SQL:\n\nSELECT daycare.Name, Count(offenders.Name) AS offenders_within_mile FROM daycare, offenders WHERE\n(((Sqr((((offenders.projx-daycare.projx)^2)+((offenders.projy-daycare.projy)^2))))<5280) AND ((daycare.projX) Is Not Null) AND ((offenders.projX) Is Not Null))\nGROUP BY daycare.Name;\n\nIt's important that your query filter out null values, which will appear in any records that you were unable to geocode. Even if only one record wasn't coded to a spot on the map, the null value will cause Access to choke.\n\nSecond: How far from each day-care center is the nearest sex offender? You'll want a query that, for each day-care center, chooses the minimum result from the distance calculation. Here's the SQL:\n\nSELECT daycare.Name, Min(Sqr((((offenders.projx-daycare.projx)^2)+(offenders.projy-daycare.projy)^2))) AS distance FROM daycare, offenders\nWHERE (((daycare.projx) Is Not Null) AND ((offenders.projx) Is Not Null))\nGROUP BY daycare.Name;\n\nIt's possible to handle these calculations with Avenue (and you don't even have to get Pythagorean to do it, because the language has a built-in distance function). But bringing it back into a database is easier, not to mention much faster. And once you've figured out how to do spatial math in Access, it's easy to change your analysis, ask different questions of your data or bring in other data, maybe the location of sex crimes or neighborhood police stations.\n\nWhat else can you do?\n\nWhy not find out how many sewer pipes dump out near your community's beaches? Or look at whether fires are happening close to the fire departments. You could add the distance calculations to an analysis of ambulance response times. And you could incorporate it into your Web site by creating searches that let users find the day-care centers closest to their homes.\n\nContact Brad Heath by e-mail at bheath@detnews.com.",
  "provenance": {
    "extracted_by": "anthropic/claude-sonnet-4-6",
    "extracted_at": "2026-07-05",
    "verified": true
  },
  "similar": [
    {
      "slug": "2004-june-making-a-point-with-geocoding",
      "score": 0.358
    },
    {
      "slug": "2004-june-sex-offenders",
      "score": 0.296
    },
    {
      "slug": "2001-septemberoctober-mapping-molesters",
      "score": 0.229
    },
    {
      "slug": "2004-june-spotting-sex-offenders",
      "score": 0.186
    },
    {
      "slug": "2000-september-mapping-bootcamp",
      "score": 0.185
    }
  ],
  "html_url": "https://dwillis.github.io/uplink/article/2003-novemberdecember-geometry-scripting-find-nearby-points.html",
  "json_url": "https://dwillis.github.io/uplink/article/2003-novemberdecember-geometry-scripting-find-nearby-points.json"
}