Modify

Opened 4 years ago

Closed 3 years ago

Last modified 3 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 3 years ago.
_11516___Sinusoidal_projection.patch (8.0 KB) - added by simon04 3 years ago.
_11516___implementation_from_the_measurement_plugin.patch (1.6 KB) - added by simon04 3 years ago.
_11516___Sinusoidal_projection-v2.patch (9.0 KB) - added by simon04 3 years ago.

Download all attachments as: .zip

Change History (25)

Changed 3 years ago by naoliv

Attachment: example.osm added

comment:1 Changed 3 years ago by naoliv

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 Changed 3 years ago by Don-vip

Keywords: area relation multipolygon added
Milestone: 16.02

comment:3 Changed 3 years ago by simon04

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

comment:4 Changed 3 years ago by bastiK

Or this:

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

comment:5 Changed 3 years ago by Klumbumbus

Cc: Klumbumbus added

comment:6 in reply to:  4 ; Changed 3 years ago by simon04

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?

comment:7 in reply to:  6 Changed 3 years ago by bastiK

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 Changed 3 years ago by simon04

In 9878/josm:

see #11516 - Add Geometry unit tests

Changed 3 years ago by simon04

comment:9 Changed 3 years ago by 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

comment:10 in reply to:  9 ; Changed 3 years ago by bastiK

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 Changed 3 years ago by simon04

Milestone: 16.0216.03

comment:12 Changed 3 years ago by simon04

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

Changed 3 years ago by simon04

comment:13 in reply to:  10 Changed 3 years ago by simon04

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 Changed 3 years ago by bastiK

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 Changed 3 years ago by simon04

In 9950/josm:

see #11516 - Add Sinusoidal projection

comment:16 Changed 3 years ago by simon04

In 9951/josm:

see #11516 - Compute closed way area using Sinusoidal projection

comment:17 Changed 3 years ago by simon04

In 9952/josm:

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

comment:18 Changed 3 years ago by Don-vip

In 9955/josm:

see #11516 - fix javadoc warning

comment:19 Changed 3 years ago by bastiK

In 9956/josm:

update reference data for Sinusoidal projection (see #11516)

comment:20 Changed 3 years ago by simon04

Resolution: fixed
Status: newclosed

comment:21 Changed 3 years ago by Don-vip

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.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.