Mapping Problem - "The type of the expression must be an array type but it resolves to float

edited June 2016 in Questions about Code

Hey guys, I'm doing a mapping project of NYC subway system using Unfolding Map Library and this error keeps popping up. The error occurred on Line 51 & 52. I am sure that the data I'm pulling out from the excel sheet are floats, since they are geographic coordinates. Also my codes looks like a mess and if anyone has suggestions please feel free to teach me!

Po

import de.fhpotsdam.unfolding.mapdisplay.*;
import de.fhpotsdam.unfolding.utils.*;
import de.fhpotsdam.unfolding.marker.*;
import de.fhpotsdam.unfolding.tiles.*;
import de.fhpotsdam.unfolding.interactions.*;
import de.fhpotsdam.unfolding.ui.*;
import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.core.*;
import de.fhpotsdam.unfolding.mapdisplay.shaders.*;
import de.fhpotsdam.unfolding.data.*;
import de.fhpotsdam.unfolding.geo.*;
import de.fhpotsdam.unfolding.texture.*;
import de.fhpotsdam.unfolding.events.*;
import de.fhpotsdam.utils.*;
import de.fhpotsdam.unfolding.providers.*;

UnfoldingMap map;
AbstractMapProvider provider1;
AbstractMapProvider provider2;
AbstractMapProvider provider3;

//create an array list to store your protests objects
ArrayList <Marker> marker = new ArrayList<Marker>();
ArrayList<Stations>stations = new ArrayList<Stations>();

Location NYCLocation = new Location(40.7833, -73.9667);

public void setup() {

  size(1280, 760, P2D);
  noStroke();

  provider1 = new StamenMapProvider.Toner();
  provider2 = new Microsoft.AerialProvider();
  provider3 = new Google.GoogleMapProvider();

  map = new UnfoldingMap(this, provider2 );
  map.setTweening(false);
  map.zoomAndPanTo(NYCLocation, 11);
  MapUtils.createDefaultEventDispatcher(this, map);

  //load the data
  Table table = loadTable("shapes.csv", "header");
  Table stops = loadTable("stops.csv", "header");

  for (int s = 0; s < stops.getRowCount (); s++) {
    TableRow hang = stops.getRow(s);

    Stations z = new Stations();

    z.distx = hang.getFloat("stop_lat")[s];
    z.disty = hang.getFloat("stop_lon")[s];

    z.stationId = hang.getString("stop_id");
    z.stopName = hang.getString("stop_name");
    float stopLat = hang.getFloat("stop_lat");
    float stopLon = hang.getFloat("stop_lon");
    z.l = new Location (stopLat, stopLon);

    stations.add(z);
  }


//line setup
  for (int i = 0; i<table.getRowCount (); i++) {
    TableRow row = table.getRow(i);

    Marker m = new Marker();

    m.lineName = row.getString("shape_id").substring(0, 1);

    float lat = row.getFloat("shape_pt_lat");
    float lon = row.getFloat("shape_pt_lon");
    m.l = new Location(lat, lon);

    marker.add(m);
  }
}

public void draw() {
  map.draw();
  background(255);

  for (Stations z : stations) {
    ScreenPosition posStations = map.getScreenPosition(z.l);
    float o = map.getZoom();
    z.stationmarker(posStations.x, posStations.y);
  }
  for (Marker m : marker) {

    ScreenPosition posMarker = map.getScreenPosition(m.l);
    float s = map.getZoom();
    m.display(posMarker.x, posMarker.y);
  }
}


void keyPressed() {
  if (key == '1') {
    map.mapDisplay.setProvider(provider2);
  } else if (key == '2') {
    map.mapDisplay.setProvider(provider3);
  } else if (key == '3') {
    map.mapDisplay.setProvider(provider1);
  }
}
Tagged:

Answers

  • Code unreadable, please format. Edit post, highlight code, press Ctrl-0.

    Then tell us the line number you are getting the error on.

  • edited June 2016 Answer ✓
    z.distx = hang.getFloat("stop_lat")[s];
    z.disty = hang.getFloat("stop_lon")[s];
    

    Method getFloat() never returns an array. Just a single float value.
    So why are you using the array access operator [] on those 2 statements? :-/

    https://Processing.org/reference/arrayaccess.html

  • Lol my fault. Now I've fixed that but the map wouldn't show up ... any idea why? :-/ Could it be the map service providers?

  • Dunno about Unfolding library. Maybe look up for other posts about it:
    https://forum.Processing.org/two/discussions/tagged/unfoldingmap

  • Do you see further error messages in the console (the black area at the bottom of Processing)? Your code shouldn't work, for instance you cannot create Markers like you do. Or is the CSV file with shapes empty, at the moment?

Sign In or Register to comment.