## geotools-gt2-users

 [Geotools-gt2-users] How can I convert mid-mif map to matrix of big cells with average territory information? From: Vitaly Baranovsky 2 - 2008-08-29 10:40:15 ```Good day! I'm very new to GIS. Please, help me... I have a map in mid-mif format. I need to create matrix, that describe average height and dominant territory type (ground, forest, water) for each 50*50m square of territory. For example, I have map of 1*1 square km. I need to divide this territory to 20*20 cells. And for each cell save to some file it's average height and dominant territory type. How can I do this? Thank you very much! -- View this message in context: http://www.nabble.com/How-can-I-convert-mid-mif-map-to-matrix-of-big-cells-with-average-territory-information--tp19216773p19216773.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. ```
 [Geotools-gt2-users] How can I convert mid-mif map to matrix of big cells with average territory information? From: Vitaly Baranovsky 2 - 2008-08-29 10:33:04 ```Good day! I'm very new to GIS. Please, help me... I have a map in mid-mif format. I need to create matrix, that describe average height and dominant territory type (ground, forest, water) for each 50*50m square of territory. For example, I have map of 1*1 square km. I need to divide this territory to 20*20 cells. And for each cell save to some file it's average height and dominant territory type. How can I do this? Thank you very much! -- View this message in context: http://www.nabble.com/How-can-I-convert-mid-mif-map-to-matrix-of-big-cells-with-average-territory-information--tp19217463p19217463.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. ```
 Re: [Geotools-gt2-users] How can I convert mid-mif map to matrix of big cells with average territory information? From: Michael Bedward - 2008-09-12 04:40:03 ```Hi Vitaly, I see you've posted this question before but didn't get any response. This probably means that there aren't many (any ?) people on the list using geotools with mapinfo data, so you're going to have to do a bit of exploring yourself... There are some mif data support classes in package org.geotools.data.mif that claim to be able to read a MIF file and get feature info. This is one of the unsupported modules and I haven't used it myself. The relevant jar name will be gt2-mif... or gt-mif... depending on which version of geotools you are using. Have a look at the javadocs at: http://javadoc.geotools.fr/2.5/org/geotools/data/mif/package-summary.html You might also consider converting you mif data to shapefile data with one of the free utilities that are floating around on the web (google is your friend for this). Geotools has very good support for shapefiles. Once you've got your feature data into geotools you can create the matrix that you need and intersect the input feature data with matrix cells. Your message implies that you want the results to be in a series of rasters (grid coverages) but I don't know if that's what you meant. Have a go at reading your feature data into geotools (if you decide to convert to shapefile first you'll find the User Manual very helpful - http://docs.codehaus.org/display/GEOTDOC/04+How+to+Read+a+Shapefile) then come back to the list with a bit more info about your output requirements. Hope this is some help Michael 2008/8/29 Vitaly Baranovsky 2 : > > Good day! > > I'm very new to GIS. Please, help me... > > I have a map in mid-mif format. I need to create matrix, that describe > average height and dominant territory type (ground, forest, water) for each > 50*50m square of territory. > > For example, I have map of 1*1 square km. I need to divide this territory to > 20*20 cells. And for each cell save to some file it's average height and > dominant territory type. How can I do this? > > Thank you very much! > -- > View this message in context: http://www.nabble.com/How-can-I-convert-mid-mif-map-to-matrix-of-big-cells-with-average-territory-information--tp19217463p19217463.html > Sent from the geotools-gt2-users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Geotools-gt2-users mailing list > Geotools-gt2-users@... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > ```
 Re: [Geotools-gt2-users] How can I convert mid-mif map to matrix of big cells with average territory information? From: Michael Bedward - 2008-10-06 23:29:04 ```Hi Vitaly, I'm replying on the user's list because it's likely that others will be able to help you more than me. I worked on FORTRAN elevation modelling code many years ago (commercial code unfortunately) but have never dealt with a raster of the size that you need. There is a module in the JGrass software that performs Kriging to fit an elevation model and there is a page that describes hacking a Java API for this module here: http://jgrasstechtips.blogspot.com/2008/06/how-to-use-openmi-enabled-kriging-in.html I think that the author is a member of this list. With a bit of googling I also found this open source code which has been described in a peer-reviewed journal and may be worth looking at (I haven't used it myself): http://www.geomath.onlinehome.de/interpolation.html Hopefully someone else on the list can also help cheers Michael 2008/10/7 Vitaly Baranovsky : > Hi Michael! > > Thank you very much for your answer! Sorry for my silence, I was busy > in another project... > > I tried to use mif package for reading mid/mif files, and it works good! > >> Once you've got your feature data into geotools you can create the >> matrix that you need and intersect the input feature data with matrix >> cells. Your message implies that you want the results to be in a >> series of rasters (grid coverages) but I don't know if that's what you >> meant > > Michael, I need two rasters: > 1) elevation model. I have mostly continuous polygons in my map, but > there is some points also... > 2) matrix of dominant ground type (water, forest, field, etc) for each > grid cell. > > I wrote program, that calculates elevation model using inverse > distance weighted algorithm. In my program I simply iterate over all > the cells and for each cell I find geometry points (for points, > polylines and polygons) inside circle with given radius, and calculate > elevation of this cell by inverse distance weighted algorithm. > > I need 16 000 x 16 000 matrix of elevation. My program build this > matrix for about 27 hours!! > > Do you know the way, how to speed up elevation model building? Maybe, > geotools or something else contains packages or plugins or utilities > for elevation model building? > ```
 Re: [Geotools-gt2-users] How can I convert mid-mif map to matrix of big cells with average territory information? From: Vitaly Baranovsky - 2008-10-08 13:23:02 Attachments: example.zip ```Thank you very much, Michael!! I will look this alogrithm later: > http://www.geomath.onlinehome.de/interpolation.html Now I'm working in another part of project. Also, I'll try krigging in grass. Thanks! Now I wrote my own alogrithm of building elevation model. It's only draft now and terrain model has some holes (I still didn't know why). So, I attach sources of my test program to this letter. When I improve this program (I think, it would be in few monthes), I send sources to this mailing list. Here is core code of interpolation algorithm: for (int y = 0; y < MapInformation.matrixHeight; y++) { double matrixY = minY + coefY * y; for (int x = 0; x < MapInformation.MATRIX_WIDTH; x++) { double matrixX = minX + coefX * x; Iterator featuresIterator = allFeatures.iterator(); double above = 0.0, beyond = 0.0; while (featuresIterator.hasNext()) { FeatureInfo fi = (FeatureInfo) featuresIterator.next(); elevation = fi.getElevation(); featureCoords = fi.getCoords(); featureCoordsLength = featureCoords.length; for (int k = 0; k < featureCoordsLength; k++) { featureCoord = featureCoords[k]; double w = featureCoord.x - matrixX; double h = featureCoord.y - matrixY; double r = w * w + h * h; if (r < SQRRADIX) { above += elevation / r; beyond += 1 / r; } } } int color = (int) (above / beyond); ................. points[MapInformation.computeCellNumber(x, y, true)] = color; } Also I wrote program, that creates for me matrix of dominant elevation types in each cell. I've zipped it too. Time for building elevation model by my code: 2 hrs 25 min. Size of elevation matrix: width - 4000 cells, height - 2667 cells. Number of features: 595. Total number of point in features: 66665. > I'm replying on the user's list because it's likely that others will > be able to help you more than me. Sorry, I didn't know my letters doesn't go to list. So, I post this letters here: ---------- Forwarded message ---------- From: Vitaly Baranovsky Date: Mon, Sep 22, 2008 at 5:14 PM Subject: Re: [Geotools-gt2-users] How can I convert mid-mif map to matrix of big cells with average territory information? To: rkgeorge@... Hi Randy! Thank you for your answer! My data is continuous. Relief layer contains only isolines as polylines. So, when I use gdal_rasterize, it draws for me only lines of isolines. And that's all. For example, all points between isoline of 150 m and 200m have zero value in target image. But I need this points have elevation between 150 and 200m (depends on distance to 150m or 200m isolines), like results of gdal_grid for sparse data. But I can't use gdal_grid, because my polylines are continuous. So, how can I create relief grid in my situation? ---------- Forwarded message ---------- From: Vitaly Baranovsky Date: Mon, Oct 6, 2008 at 7:16 PM Subject: Re: [Geotools-gt2-users] How can I convert mid-mif map to matrix of big cells with average territory information? To: Michael Bedward Hi Michael! Thank you very much for your answer! Sorry for my silence, I was busy in another project... I tried to use mif package for reading mid/mif files, and it works good! > Once you've got your feature data into geotools you can create the > matrix that you need and intersect the input feature data with matrix > cells. Your message implies that you want the results to be in a > series of rasters (grid coverages) but I don't know if that's what you > meant Michael, I need two rasters: 1) elevation model. I have mostly continuous polygons in my map, but there is some points also... 2) matrix of dominant ground type (water, forest, field, etc) for each grid cell. I wrote program, that calculates elevation model using inverse distance weighted algorithm. In my program I simply iterate over all the cells and for each cell I find geometry points (for points, polylines and polygons) inside circle with given radius, and calculate elevation of this cell by inverse distance weighted algorithm. I need 16 000 x 16 000 matrix of elevation. My program build this matrix for about 27 hours!! Do you know the way, how to speed up elevation model building? Maybe, geotools or something else contains packages or plugins or utilities for elevation model building? On Tue, Oct 7, 2008 at 2:26 AM, Michael Bedward wrote: > Hi Vitaly, > > I'm replying on the user's list because it's likely that others will > be able to help you more than me. > > I worked on FORTRAN elevation modelling code many years ago > (commercial code unfortunately) but have never dealt with a raster of > the size that you need. There is a module in the JGrass software that > performs Kriging to fit an elevation model and there is a page that > describes hacking a Java API for this module here: > > http://jgrasstechtips.blogspot.com/2008/06/how-to-use-openmi-enabled-kriging-in.html > > I think that the author is a member of this list. > > With a bit of googling I also found this open source code which has > been described in a peer-reviewed journal and may be worth looking at > (I haven't used it myself): > > http://www.geomath.onlinehome.de/interpolation.html > > Hopefully someone else on the list can also help > > cheers > Michael > > > 2008/10/7 Vitaly Baranovsky : >> Hi Michael! >> >> Thank you very much for your answer! Sorry for my silence, I was busy >> in another project... >> >> I tried to use mif package for reading mid/mif files, and it works good! >> >>> Once you've got your feature data into geotools you can create the >>> matrix that you need and intersect the input feature data with matrix >>> cells. Your message implies that you want the results to be in a >>> series of rasters (grid coverages) but I don't know if that's what you >>> meant >> >> Michael, I need two rasters: >> 1) elevation model. I have mostly continuous polygons in my map, but >> there is some points also... >> 2) matrix of dominant ground type (water, forest, field, etc) for each >> grid cell. >> >> I wrote program, that calculates elevation model using inverse >> distance weighted algorithm. In my program I simply iterate over all >> the cells and for each cell I find geometry points (for points, >> polylines and polygons) inside circle with given radius, and calculate >> elevation of this cell by inverse distance weighted algorithm. >> >> I need 16 000 x 16 000 matrix of elevation. My program build this >> matrix for about 27 hours!! >> >> Do you know the way, how to speed up elevation model building? Maybe, >> geotools or something else contains packages or plugins or utilities >> for elevation model building? >> > -- With best regards, Vitaly Baranovsky ```
 Re: [Geotools-gt2-users] How can I convert mid-mif map to matrix of big cells with average territory information? From: Michael Bedward - 2008-10-08 23:48:45 ```Hi Vitaly, Many thanks for posting your code to the list - that's always good because it becomes a resource for other users when they are searching the archives. Let us know how you get on at some stage - I'll be very interested to hear about it. One more page that may be useful for code or ideas: http://www.ee.ucl.ac.uk/~mflanaga/java/BiCubicSpline.html It has java code for fitting cubic splines to 2D data. This is similar in concept to the FORTRAN elevation modelling code that I worked on last century :) Michael 2008/10/9 Vitaly Baranovsky : > Thank you very much, Michael!! > > I will look this alogrithm later: >> http://www.geomath.onlinehome.de/interpolation.html > Now I'm working in another part of project. > > Also, I'll try krigging in grass. Thanks! > > Now I wrote my own alogrithm of building elevation model. It's only > draft now and terrain model has some holes (I still didn't know why). > So, I attach sources of my test program to this letter. When I improve > this program (I think, it would be in few monthes), I send sources to > this mailing list. > > Here is core code of interpolation algorithm: > for (int y = 0; y < MapInformation.matrixHeight; y++) { > double matrixY = minY + coefY * y; > for (int x = 0; x < MapInformation.MATRIX_WIDTH; x++) { > double matrixX = minX + coefX * x; > Iterator featuresIterator = allFeatures.iterator(); > double above = 0.0, beyond = 0.0; > while (featuresIterator.hasNext()) { > FeatureInfo fi = (FeatureInfo) featuresIterator.next(); > elevation = fi.getElevation(); > featureCoords = fi.getCoords(); > featureCoordsLength = featureCoords.length; > for (int k = 0; k < featureCoordsLength; k++) { > featureCoord = featureCoords[k]; > double w = featureCoord.x - matrixX; > double h = featureCoord.y - matrixY; > double r = w * w + h * h; > if (r < SQRRADIX) { > above += elevation / r; > beyond += 1 / r; > } > } > } > > int color = (int) (above / beyond); > ................. > points[MapInformation.computeCellNumber(x, y, true)] = color; > } > Also I wrote program, that creates for me matrix of dominant elevation > types in each cell. I've zipped it too. > Time for building elevation model by my code: 2 hrs 25 min. > Size of elevation matrix: width - 4000 cells, height - 2667 cells. > Number of features: 595. Total number of point in features: 66665. > > >> I'm replying on the user's list because it's likely that others will >> be able to help you more than me. > > Sorry, I didn't know my letters doesn't go to list. So, I post this > letters here: > ```
 Re: [Geotools-gt2-users] How can I convert mid-mif map to matrix of big cells with average territory information? From: Michael Bedward - 2008-10-09 12:22:02 ```Hi Vitaly, Keep in mind that ArcInfo is written in C or something similar, so it's bound to faster than Java. The most obvious thing to tweak in your program is reducing the time spent iterating through input features. You could set a distance threshold beyond which you don't include features in the inverse distance calculation. Then, at each point, you can get the subset of features within that threshold using a filter (see this page in the user guide for examples: http://docs.codehaus.org/display/GEOTDOC/Filter+Examples). Taking that a bit futher, divide your matrix into tiles, then use a filter to subset the features that are within the threshold distance of each tile and do the calculations for the points in that tile. These are just off the top of my head and I'm sure you or someone else here will be able to improve on them. Michael 2008/10/9 Vitaly Baranovsky : > Thanks for the link, Michael! > > I made some measurements with ArcInfo. With ArcInfo I can build > elevation matrix with size 4000x2667 in about 10 min. My interpolation > algorithm takes 2hrs 25 min. It is very long time for building > elevation model. > > How can I optimize my inverse distance weighting interpolation algorithm? > > On Thu, Oct 9, 2008 at 2:48 AM, Michael Bedward > wrote: >> Hi Vitaly, >> >> Many thanks for posting your code to the list - that's always good >> because it becomes a resource for other users when they are searching >> the archives. >> >> Let us know how you get on at some stage - I'll be very interested to >> hear about it. >> >> One more page that may be useful for code or ideas: >> http://www.ee.ucl.ac.uk/~mflanaga/java/BiCubicSpline.html >> >> It has java code for fitting cubic splines to 2D data. This is >> similar in concept to the FORTRAN elevation modelling code that I >> worked on last century :) >> >> Michael >> >> >> 2008/10/9 Vitaly Baranovsky : >>> Thank you very much, Michael!! >>> >>> I will look this alogrithm later: >>>> http://www.geomath.onlinehome.de/interpolation.html >>> Now I'm working in another part of project. >>> >>> Also, I'll try krigging in grass. Thanks! >>> >>> Now I wrote my own alogrithm of building elevation model. It's only >>> draft now and terrain model has some holes (I still didn't know why). >>> So, I attach sources of my test program to this letter. When I improve >>> this program (I think, it would be in few monthes), I send sources to >>> this mailing list. >>> >>> Here is core code of interpolation algorithm: >>> for (int y = 0; y < MapInformation.matrixHeight; y++) { >>> double matrixY = minY + coefY * y; >>> for (int x = 0; x < MapInformation.MATRIX_WIDTH; x++) { >>> double matrixX = minX + coefX * x; >>> Iterator featuresIterator = allFeatures.iterator(); >>> double above = 0.0, beyond = 0.0; >>> while (featuresIterator.hasNext()) { >>> FeatureInfo fi = (FeatureInfo) featuresIterator.next(); >>> elevation = fi.getElevation(); >>> featureCoords = fi.getCoords(); >>> featureCoordsLength = featureCoords.length; >>> for (int k = 0; k < featureCoordsLength; k++) { >>> featureCoord = featureCoords[k]; >>> double w = featureCoord.x - matrixX; >>> double h = featureCoord.y - matrixY; >>> double r = w * w + h * h; >>> if (r < SQRRADIX) { >>> above += elevation / r; >>> beyond += 1 / r; >>> } >>> } >>> } >>> >>> int color = (int) (above / beyond); >>> ................. >>> points[MapInformation.computeCellNumber(x, y, true)] = color; >>> } >>> Also I wrote program, that creates for me matrix of dominant elevation >>> types in each cell. I've zipped it too. >>> Time for building elevation model by my code: 2 hrs 25 min. >>> Size of elevation matrix: width - 4000 cells, height - 2667 cells. >>> Number of features: 595. Total number of point in features: 66665. >>> >>> >>>> I'm replying on the user's list because it's likely that others will >>>> be able to help you more than me. >>> >>> Sorry, I didn't know my letters doesn't go to list. So, I post this >>> letters here: >>> >> > > > > -- > With best regards, > Vitaly Baranovsky > ```