NetLogo / NetLogo/GIS-Extension

`gis:create-turtles-inside-polygon` fails with `Extension exception: Index 0 out of bounds for length 0`

Open
#44 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
36
Forks
23
PR merge metrics
No merged PRs in 30d

Description

I'm using the gis:create-turtles-inside-polygon function with the GIS Extension of NetLogo 6.3.0. I follow the example listed in the docs, with a few lines of code added to place each agent in the center of that polygon. That also prevents all agents outside my world envelope from being created.

to setup-spots
  ;; For each parking space, determine the centroid, convert to x,y coordinates (list with 2 elements),
  ;; and create a turtle in the center of that polygon 
  foreach gis:feature-list-of parking-dataset [ this-vector-feature ->
    let center gis:centroid-of this-vector-feature
    let loc gis:location-of center
    if  length loc >= 2 [
      gis:create-turtles-inside-polygon this-vector-feature spots 1 [setxy item 0 loc item 1 loc]
    ]
  ]
end

However, it fails with a weird error: Extension exception: Index 0 out of bounds for length 0. I tried about everything, but it just keeps failing. Could it be my data source?

@JamesHovet, since you wrote this function, do you have any idea what's going on? Or @LaCuneta?

Here are my model and data: NetLogo-GIS-test.zip

Model code
extensions [gis]
globals [parking-dataset projection]
breed [spots spot]
spots-own [AMENITY]

to setup
  clear-all
  load
  draw
  setup-spots
end

to load
  set projection "WGS_84_Geographic"
  set parking-dataset gis:load-dataset "export2.geojson"
  gis:set-world-envelope (list 5.671533 5.684606 52.026888 52.019735)
end

to setup-spots
  ;; For each parking space, determine the centroid, convert to x,y coordinates (list with 2 elements),
  ;; and create a turtle in the center of that polygon 
  foreach gis:feature-list-of parking-dataset [ this-vector-feature ->
    let center gis:centroid-of this-vector-feature
    let loc gis:location-of center
    if  length loc >= 2 [
      gis:create-turtles-inside-polygon this-vector-feature spots 1;; [setxy item 0 loc item 1 loc]
    ]
  ]
end

to draw
  gis:set-drawing-color red
  gis:fill parking-dataset 0
end

to clear
  clear-all
end
Full error

Extension exception: Index 0 out of bounds for length 0
error while observer running GIS:CREATE-TURTLES-INSIDE-POLYGON
called by (anonymous command: [ this-vector-feature -> let center gis:centroid-of this-vector-feature let loc gis:location-of center if length loc >= 2 [ gis:create-turtles-inside-polygon this-vector-feature spots 1 ] ])
called by procedure SETUP-SPOTS
called by procedure SETUP
called by Button 'setup'

org.nlogo.nvm.WrappedExtensionException: Extension exception: Index 0 out of bounds for length 0
at org.nlogo.nvm.AnonymousCommand.perform(AnonymousProcedure.scala:212)
at org.nlogo.nvm.AnonymousCommand.perform(AnonymousProcedure.scala:184)
at org.nlogo.prim.etc._foreach.perform(_foreach.scala:38)
at org.nlogo.nvm.Context.stepConcurrent(Context.java:107)
at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.scala:65)
at org.nlogo.job.JobThread.runPrimaryJobs(JobThread.scala:133)
at org.nlogo.job.JobThread.$anonfun$run$1(JobThread.scala:68)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
at scala.util.control.Exception$Catch.apply(Exception.scala:228)
at org.nlogo.api.Exceptions$.handling(Exceptions.scala:41)
at org.nlogo.job.JobThread.run(JobThread.scala:66)
Caused by: org.nlogo.api.ExtensionException: Index 0 out of bounds for length 0
at com.vividsolutions.jts.geom.GeometryCollection.getGeometryN(GeometryCollection.java:138)
at org.myworldgis.netlogo.VectorFeature.getRandomTriangleWeightedByArea(VectorFeature.java:347)
at org.myworldgis.netlogo.VectorFeature.getRandomPointInsidePolygon(VectorFeature.java:359)
at org.myworldgis.netlogo.CreateTurtlesInsidePolygon$TurtlesInsidePolygon.performInternal(CreateTurtlesInsidePolygon.java:63)
at org.myworldgis.netlogo.CreateTurtlesInsidePolygon$TurtlesInsidePolygonAutomatic.performInternal(CreateTurtlesInsidePolygon.java:83)
at org.myworldgis.netlogo.GISExtension$Command.perform(GISExtension.java:61)
at org.nlogo.prim._extern.perform(_extern.java:36)
at org.nlogo.nvm.Context.runExclusive(Context.java:133)
at org.nlogo.nvm.AnonymousCommand.perform(AnonymousProcedure.scala:206)
... 10 more

NetLogo 6.3.0
main: org.nlogo.app.AppFrame
thread: JobThread
OpenJDK 64-Bit Server VM 17.0.3 (BellSoft; 17.0.3+7-LTS)
operating system: Windows 11 10.0 (amd64 processor)
Scala version 2.12.16
JOGL: (3D View not initialized)
OpenGL Graphics: (3D View not initialized)
model: GIS_test

01:17:21.163 RuntimeErrorEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
01:17:21.147 JobRemovedEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) JobThread
01:17:21.147 OutputEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
01:17:21.139 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
01:17:21.139 TickStateChangeEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) JobThread
01:17:21.139 OutputEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
01:17:21.139 AddJobEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0
01:17:21.089 InputBoxLoseFocusEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0
01:17:21.038 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
01:17:20.823 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the GIS_test model with export2.geojson and reproduce the failure in gis:create-turtles-inside-polygon. Read CreateTurtlesInsidePolygon.java and VectorFeature.java, especially getRandomTriangleWeightedByArea and getRandomPointInsidePolygon, using the stack trace as the entry point. Done means the supplied model no longer raises the empty-geometry exception and the behavior for the affected polygon data is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.