Modify

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#11516 closed enhancement (fixed)

Compute areasize() for multipolygons

Reported by: naoliv Owned by: team
Priority: normal Milestone: 16.04
Component: Core validator Version:
Keywords: mapcss area relation multipolygon Cc: Klumbumbus

Description

Shouldn't areasize() also return the area size of relations?

The area selector matches "any area regardless of whether the area border is only modelled with a single way or with a set of ways glued together with a relation" while areasize() only works with a closed way.

Attachments (4)

example.osm (2.1 KB ) - added by naoliv 8 years ago.
_11516___Sinusoidal_projection.patch (8.0 KB ) - added by simon04 8 years ago.
_11516___implementation_from_the_measurement_plugin.patch (1.6 KB ) - added by simon04 8 years ago.
_11516___Sinusoidal_projection-v2.patch (9.0 KB ) - added by simon04 8 years ago.

Download all attachments as: .zip

Change History (25)

by naoliv, 8 years ago

Attachment: example.osm added

comment:1 by naoliv, 8 years ago

Using the attached example file and this example mapcss rule it should match all the 3 areas.

area:closed[foo = yes][eval(areasize()) > 1] {
        throwWarning: tr("foo");
}

comment:2 by Don-vip, 8 years ago

Keywords: area relation multipolygon added
Milestone: 16.02

comment:3 by simon04, 8 years ago

An implementation could be taken from or be inspired by the measurement plugin, MeasurementDialog.java

comment:4 by bastiK, 8 years ago

Or this:

Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r);
double area = 0;
for (PolyData pd : multipolygon.getCombinedPolygons()) {
    area += pd.getAreaAndPerimeter().getArea();
}

comment:5 by Klumbumbus, 8 years ago

Cc: Klumbumbus added

in reply to:  4 ; comment:6 by simon04, 8 years ago

Replying to bastiK:

org.openstreetmap.josm.tools.Geometry#getAreaAndPerimeter returns the area wrt to the current projection. Thus, the value cannot be directly represented in the user's SystemOfMeasurement. Can we somehow handle this?

in reply to:  6 comment:7 by bastiK, 8 years ago

To get a meaningful area in square meters, the coordinates need to be projected using an equal-area projection. Measurement plugin uses Sinusoidal projection. Cylindrical equal-area projection is even simpler.

The way this is done in Geometry (calcX/calcY) is incorrect: The author invented a funny projection that calculates the easting of a point (lat/lon) as great circle distance to the point (lat/0.0) and northing as great circle distance to the point (0.0/lon). This is more complicated and less correct than the projections mentioned above. Plus it is broken for areas crossing the prime meridian. I committed the code myself in [4085], so unfortunately, I have no one to blame. ;-)

Replying to simon04:

org.openstreetmap.josm.tools.Geometry#getAreaAndPerimeter returns the area wrt to the current projection. Thus, the value cannot be directly represented in the user's SystemOfMeasurement. Can we somehow handle this?

Right, the values are needed in units of the current projection for map rendering. Not sure if this can be merged somehow, but it may be simpler to add an extra method to Geometry which copies and adapts the code in PolyData.getAreaAndPerimeter.

comment:8 by simon04, 8 years ago

In 9878/josm:

see #11516 - Add Geometry unit tests

comment:9 by simon04, 8 years ago

For the outer ring of source:trunk/test/data/create_multipolygon.osm,

  1. the current implementation gives 5721923.660644531
  2. the implementation from the measurement plugin gives 5736957.869628906
  3. my attempt to implement https://en.wikipedia.org/wiki/Sinusoidal_projection gives 5757045.313964844

in reply to:  9 ; comment:10 by bastiK, 8 years ago

Replying to simon04:

For the outer ring of source:trunk/test/data/create_multipolygon.osm,

  1. the current implementation gives 5721923.660644531
  2. the implementation from the measurement plugin gives 5736957.869628906
  3. my attempt to implement https://en.wikipedia.org/wiki/Sinusoidal_projection gives 5757045.313964844

The difference of the last two comes from different earth radii used as input. Regarding the patch: The EastNorth coordinates in the current projection are cached and should be used in this calculation (runs during rendering). Implementation of sinusoidal should either include ellipsoidal case (see geotools implementation) or throw an error when ellipsoid is not spherical.

comment:11 by simon04, 8 years ago

Milestone: 16.0216.03

comment:12 by simon04, 8 years ago

Summary: areasize() not working with relationsCompute areasize() for multipolygons
Type: defectenhancement

in reply to:  10 comment:13 by simon04, 8 years ago

bastiK, thank you for the review.

What do you think? Is the order phi/lambda and east/north correct in the (inv-)project methods?

comment:14 by bastiK, 8 years ago

Without testing, I would say

  return new double[]{east / cos(north), north};

should be

  return new double[]{north, east / cos(north)};

Otherwise +1.

As you may be aware, with this patch it uses ellipsoidal case of the projection, which is even more precise than the method of measurement plugin. The efficiency is fine too - the forward projections is fairly simple and overall it should be faster that what we have at the moment.

comment:15 by simon04, 8 years ago

In 9950/josm:

see #11516 - Add Sinusoidal projection

comment:16 by simon04, 8 years ago

In 9951/josm:

see #11516 - Compute closed way area using Sinusoidal projection

comment:17 by simon04, 8 years ago

In 9952/josm:

see #11516 - Compute multipolygon area, include in MapCSS, JOSM search

comment:18 by Don-vip, 8 years ago

In 9955/josm:

see #11516 - fix javadoc warning

comment:19 by bastiK, 8 years ago

In 9956/josm:

update reference data for Sinusoidal projection (see #11516)

comment:20 by simon04, 8 years ago

Resolution: fixed
Status: newclosed

comment:21 by Don-vip, 8 years ago

Milestone: 16.0316.04

Milestone renamed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.