MySQL Forums
Forum List  »  General

Re: Area "costs"
Posted by: Rick James
Date: April 18, 2013 08:21AM

> I want to have a database

First you create a database, then you put table(s) in it.
CREATE DATABASE foo;
CREATE TABLE Areas ( ... );

> where there are multiple [rectangular] areas that could potentially overlap each other,
CREATE TABLE Areas (
xmin INT NOT NULL,
xmax INT NOT NULL,
ymin INT NOT NULL,
ymax INT NOT NULL,
...
);

> every area has a "cost" per square pixel,

Add another field:
cost INT UNSIGNED NOT NULL,
(or maybe FLOAT or DECIMAL)

> so you can get the cost at a certain point

SELECT SUM(cost) -- assuming the areas overlay and you need to add up the costs
FROM Areas -- table name
WHERE -- now, let's limit to one pixel
X BETWEEN xmin and xmax -- the pixel you are asking about is X,Y
AND Y BETWEEN ymin and ymax;

> or measure the cost of an entire area while ignoring the parts that are being overlapped,

Unclear -- If they overlap, which cost should be used? Stackoverflow picked the largest (MAX).

> you could also get the average of the total cost

Count each pixel equally? Or count each area equally?

See if these comments get you farther.

Options: ReplyQuote


Subject
Written By
Posted
April 17, 2013 10:52AM
Re: Area "costs"
April 18, 2013 08:21AM
April 18, 2013 10:30AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.