Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

How to tackle 2-D and 3-D space in data ? lets say you are working on a power grid problem. You need to represent Towers; transmission lines; transformers and every thing else in a 2-D space. How would you design a Data Model for this 2-D space ? I can use a

class tower  {
int x_cor;
int y_cor;
string power_properties

But how to represent the ... say map of the power grid itself ? is there some standard solution to this ? some logical template people follow here ?

i want to be able to slice this map by shape or area etc; i should be able to compose small maps to make a large one .. So what is the solution here ?? By the way i am not working on a power-grid project (LOL) so please keep answers generic ..

P.S. non-noobs please help me make the question better.

share|improve this question
add comment

4 Answers

up vote 2 down vote accepted

I do a lot of work with Geographic Information Systems (GIS). Part of working in this domain requires handling and storing all sorts of spatial data, which we usually leave up to software vendors like ESRI or use open source solutions like GDAL. GDAL can also be plugged into C++ and python programs easily.

There are also several spatial databases out there like Oracle Spatial, Postgis, and Sql Server Spatial which will handle storage of this data as well as processing of it (find me all transmission towers that are inside of this area) through an extension of SQL syntax. These spatial databases tend to implement several operations that you would normally find in a computational geometry book.

GIS systems like ArcGIS and qGIS also provide the ability to create and print visual maps and save maps from your data as part of the solution.

In short I'm advocating against reinventing the wheel and borrowing functionality from these well tested solutions to spatial decision problems.

share|improve this answer
THANKS A TONNE MAN –  Ritwik G Jun 10 '11 at 15:39
add comment

What I am going to say probably sounds very generic, and to a degree it is, but it can be applied to any engineering problem.

Software is generally used to deal with problems in the real world. In consequence it models those parts of the real world it deals with. The more accurate the model is, the better you can deal with the real problem, but at the same time generally the complexity of the model increases.

Your sample class is obviously an extremely simple model of a tower, more like a base class. Before you can make any further decisions of the modeling your 2d and 3d data, you need to ask yourself which aspects of this power grid to I need to deal with? And which properties do I need to for that?

Developing an appropriate data model can be done as a bottom-up approach or a top down approach. The bottom-up usually works well if you have a good understanding of the problem domain, and the data structures and class structures are inherently clear. However, if that is not the case, the top-down approach can also work, where you basically first create descriptions of all entities involved and then try and find some structure. Surprisingly you will find that often things you wouldn't normally have thought of as being of the same kind turn out to share properties or attributes.

Be prepared for a lot of refactoring when using the top-down approach. As your understanding of the problem domain grows, so will your understanding of the required data model.

Plus: for any work in 2D or 3D data I would recommend reading up about directed and undirected graphs.

share|improve this answer
add comment

Simple Features Data Model is both an OGC and ISO standard (ISO 19125) that specifies a common storage model of mostly two-dimensional geographical data (point, line, polygon, multi-point, multi-line, etc.).

Most of the spatial extensions for SQL (Oracle Spatial, Postgis, MySQL Spatial Extensions, etc...) implement to varying degree this Standard.

share|improve this answer
add comment

You could create a class for the map, with functions to determine the towers within an area:

Class Map{
Tower[] towers;
Tower[] towersInArea(int x1, int y1, int x2, int y2)
share|improve this answer
-1 you have take a schoolboys view of the problem –  Ritwik G Jun 10 '11 at 7:22
+1, with the question phrased as is, this is a simple but effective solution –  blubb Jun 10 '11 at 9:24
@simon Please try to read the question more carefully. think deeply. and pray suggest how i can make the question appeal to your senses a bit more ? –  Ritwik G Jun 10 '11 at 11:55
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.