{
  "$schema": "https://gismap.online/schemas/agent-recipe-v1.schema.json",
  "schemaVersion": 1,
  "id": "dot-density",
  "title": "Dot-density points from polygon counts",
  "status": "available",
  "question": "Can an AI agent make a dot-density map, one dot per so many people, from polygons with counts?",
  "answer": "Yes. The random-points analysis step places one random dot per amount of a polygon's numeric field (one per 50 people, say) inside each polygon, spread evenly by area. The generator is seeded, so everyone who opens the link sees the same dots. The dots carry represents, so a following hexbin step can sum them into equal-area hexagons.",
  "triggers": [
    "Make a dot-density map of population",
    "One dot per 100 people from these census tracts",
    "Turn these polygons with counts into points I can bin"
  ],
  "inputTypes": [
    "Polygon FeatureServer layer with a count field",
    "Polygon GeoJSON with a count field"
  ],
  "inputs": {
    "required": [
      {
        "name": "source",
        "description": "A polygon layer."
      },
      {
        "name": "field",
        "description": "A numeric count field, such as population."
      }
    ],
    "optional": [
      {
        "name": "unitsPerPoint",
        "description": "Amount per dot; leave out for about 10,000 dots. At most 100,000 dots."
      },
      {
        "name": "seed",
        "description": "Whole number; change it for a different but equally valid layout."
      },
      {
        "name": "area",
        "description": "\"view\" reads only polygons in the current map view."
      },
      {
        "name": "visible",
        "description": "false on the step hides the dots, such as when a hexbin step bins them."
      }
    ]
  },
  "capabilities": [
    "renderer-spec"
  ],
  "engines": [
    "maplibre",
    "arcgis"
  ],
  "steps": [
    {
      "stage": "discover",
      "action": "Read llms.txt, this recipe and api/capabilities.json; note the engine and execution environment you actually have.",
      "interfaces": [
        "declarative-url"
      ],
      "references": [
        "https://gismap.online/llms.txt",
        "https://gismap.online/api/capabilities.json",
        "https://gismap.online/api/manifest.json"
      ]
    },
    {
      "stage": "inspect",
      "action": "Read the source metadata: geometry type, field names and types, spatial reference, extent, sentinels and query support. Query real values before filtering; never invent fields.",
      "interfaces": [
        "declarative-url",
        "standalone-js",
        "in-browser-api"
      ],
      "references": [
        "<layer URL>?f=pjson",
        "sources.inspect",
        "sources.detectSentinels",
        "layers.metadata"
      ]
    },
    {
      "stage": "plan",
      "action": "Confirm polygon geometry and a count field (not a rate or percentage). Sum the field over the filter to choose unitsPerPoint: total ÷ unitsPerPoint is the dot count, which should stay under 100,000. Up to 50,000 polygons are read; filter with where for bigger layers.",
      "interfaces": [
        "standalone-js"
      ],
      "references": [
        "sources.inspect"
      ]
    },
    {
      "stage": "validate",
      "action": "Add { \"operation\": \"random-points\", \"input\": 0, \"options\": { \"field\": \"POP\", \"unitsPerPoint\": 50, \"seed\": 1 } } and validate the spec.",
      "interfaces": [
        "standalone-js",
        "in-browser-api"
      ],
      "references": [
        "mapSpec.validate"
      ]
    },
    {
      "stage": "execute",
      "action": "Return the #map=json: link, or run analysis.run(\"random-points\", ...) in a page. To bin the dots, add a hexbin step with input { \"step\": 0 } and statistic sum of represents.",
      "interfaces": [
        "declarative-url",
        "in-browser-api"
      ],
      "references": [
        "https://gismap.online/schemas/map-v1.schema.json",
        "mapSpec.createLink",
        "analysis.run"
      ]
    },
    {
      "stage": "verify",
      "action": "Open the link and check the dot count in the summary against total ÷ unitsPerPoint, and that it does not start with \"Incomplete:\".",
      "interfaces": [
        "in-browser-api"
      ],
      "references": [
        "layers.list"
      ]
    },
    {
      "stage": "share",
      "action": "Return the link and say that dots are placed at random inside each polygon, not at addresses.",
      "interfaces": [
        "declarative-url"
      ],
      "references": [
        "mapSpec.createLink"
      ]
    }
  ],
  "artifact": {
    "type": "map",
    "schema": "https://gismap.online/schemas/map-v1.schema.json",
    "structure": "map-v1 with a polygon layer and an analysis step { operation: \"random-points\" }."
  },
  "outputs": [
    {
      "format": "Interactive dot-density map link",
      "interface": "declarative-url",
      "interactive": true,
      "reference": "mapSpec.createLink"
    }
  ],
  "verification": [
    "Field is a count",
    "Dot count ≈ total ÷ unitsPerPoint",
    "No \"Incomplete:\" in the summary, or the gap is reported",
    "Map text says dots are random within polygons"
  ],
  "limitations": [
    "Dots are random positions inside each polygon, not real locations: never present them as addresses.",
    "Rates and percentages cannot become dots; use a count.",
    "Reads up to 50,000 polygons and makes up to 100,000 dots."
  ],
  "recovery": [
    "\"too many points\": raise unitsPerPoint to the amount the message suggests.",
    "\"Incomplete:\": filter the layer with where, or use area \"view\" with a closer camera."
  ],
  "examples": [
    {
      "checkedOn": "2026-11-20",
      "checkedVersion": "0.54.0",
      "title": "Ventura County, one dot per 50 people",
      "prompt": "Make a dot-density map of Ventura County's population from census blocks, one dot per 50 people.",
      "dataset": [
        {
          "label": "California Census 2020 Redistricting Blocks (Esri, U.S. Census Bureau)",
          "url": "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/California_Census_2020_Redistricting_Blocks/FeatureServer/0"
        }
      ],
      "url": "https://gismap.online/#map=json:%7B%22version%22%3A1%2C%22title%22%3A%22Ventura%20County%20population%2C%20one%20dot%20per%2050%20people%22%2C%22basemap%22%3A%22gray-vector%22%2C%22camera%22%3A%7B%22center%22%3A%5B-119.1%2C34.25%5D%2C%22zoom%22%3A9.6%7D%2C%22layers%22%3A%5B%7B%22url%22%3A%22https%3A%2F%2Fservices.arcgis.com%2FP3ePLMYs2RVChkJx%2Farcgis%2Frest%2Fservices%2FCalifornia_Census_2020_Redistricting_Blocks%2FFeatureServer%2F0%22%2C%22type%22%3A%22feature%22%2C%22title%22%3A%22Ventura%20County%20census%20blocks%20(2020)%22%2C%22where%22%3A%22County_Name%20%3D%20'Ventura%20County'%20AND%20P0010001%20%3E%200%22%2C%22opacity%22%3A0.35%2C%22renderer%22%3A%7B%22type%22%3A%22simple%22%2C%22color%22%3A%22%23c9cdd2%22%2C%22outline%22%3A%22%23ffffff%22%7D%7D%5D%2C%22analysis%22%3A%5B%7B%22operation%22%3A%22random-points%22%2C%22input%22%3A0%2C%22options%22%3A%7B%22field%22%3A%22P0010001%22%2C%22unitsPerPoint%22%3A50%2C%22seed%22%3A1%7D%2C%22title%22%3A%22People%2C%20one%20dot%20per%2050%22%7D%5D%7D",
      "spec": {
        "version": 1,
        "title": "Ventura County population, one dot per 50 people",
        "basemap": "gray-vector",
        "camera": {
          "center": [
            -119.1,
            34.25
          ],
          "zoom": 9.6
        },
        "layers": [
          {
            "url": "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/California_Census_2020_Redistricting_Blocks/FeatureServer/0",
            "type": "feature",
            "title": "Ventura County census blocks (2020)",
            "where": "County_Name = 'Ventura County' AND P0010001 > 0",
            "opacity": 0.35,
            "renderer": {
              "type": "simple",
              "color": "#c9cdd2",
              "outline": "#ffffff"
            }
          }
        ],
        "analysis": [
          {
            "operation": "random-points",
            "input": 0,
            "options": {
              "field": "P0010001",
              "unitsPerPoint": 50,
              "seed": 1
            },
            "title": "People, one dot per 50"
          }
        ]
      },
      "status": "rendered",
      "checks": [
        "Opened on MapLibre: 7,843 blocks loaded and 16,886 dots drawn (843,843 people ÷ 50 ≈ 16,877); no console errors.",
        "The block outlines follow the publisher's scale range and are hidden at the opening zoom; zoom in to see them.",
        "ArcGIS engine not checked."
      ]
    }
  ],
  "lastTestedVersion": "0.53.0",
  "resultStatuses": [
    "prepared",
    "validated",
    "loaded",
    "rendered",
    "verified",
    "partial",
    "failed"
  ]
}
